Esempio n. 1
0
        public static void ListColumnClick(ColumnClickEventArgs e)
        {
            ListViewEx ShortLivedListView = OwnerWindow.ShortLivedListView;

            if (ShortLivedListView.Items.Count == 0)
            {
                return;
            }

            if (e.Column == ColumnToSortBy)
            {
                ColumnSortModeAscending = !ColumnSortModeAscending;
            }
            else
            {
                ColumnToSortBy          = e.Column;
                ColumnSortModeAscending = false;
            }

            int[] NewColumnMapping = new int[ShortLivedColumnMapping.Length];
            for (int MappingIndex = 0; MappingIndex < NewColumnMapping.Length; MappingIndex++)
            {
                NewColumnMapping[MappingIndex] = ShortLivedColumnMapping[MappingIndex];

                if (ShortLivedColumnMapping[MappingIndex] < ShortLivedColumnMapping[e.Column])
                {
                    NewColumnMapping[MappingIndex]++;
                }
            }
            NewColumnMapping[e.Column] = 0;

            // copy items to a temp array because the ListViewItemCollection doesn't have a Sort method
            ListViewItem[] TempItems  = new ListViewItem[ShortLivedListView.Items.Count];
            uint[]         TempValues = new uint[ShortLivedColumnMapping.Length];
            for (int MappingIndex = 0; MappingIndex < TempItems.Length; MappingIndex++)
            {
                FShortLivedCallStackTag Tag = ( FShortLivedCallStackTag )ShortLivedListView.Items[MappingIndex].Tag;
                for (int j = 0; j < Tag.ColumnValues.Length; j++)
                {
                    TempValues[NewColumnMapping[j]] = Tag.ColumnValues[ShortLivedColumnMapping[j]];
                }

                uint[] OldValues = Tag.ColumnValues;
                Tag.ColumnValues = TempValues;
                // reuse old array for next value swap
                TempValues = OldValues;

                TempItems[MappingIndex] = ShortLivedListView.Items[MappingIndex];
            }

            Array.Sort <ListViewItem>(TempItems, CompareShortLivedColumns);

            ShortLivedListView.BeginUpdate();
            ShortLivedListView.Items.Clear();
            ShortLivedListView.Items.AddRange(TempItems);
            ShortLivedListView.SetSortArrow(ColumnToSortBy, ColumnSortModeAscending);
            ShortLivedListView.EndUpdate();

            ShortLivedColumnMapping = NewColumnMapping;
        }
Esempio n. 2
0
            public int Compare(object A, object B)
            {
                FShortLivedCallStackTag AValues = (FShortLivedCallStackTag)((ListViewItem)A).Tag;
                FShortLivedCallStackTag BValues = (FShortLivedCallStackTag)((ListViewItem)B).Tag;

                foreach (int ColumnIndex in ColumnSortOrder)
                {
                    if (AValues.ColumnValues[ColumnIndex] < BValues.ColumnValues[ColumnIndex])
                    {
                        return(ColumnSortModeAscending ? -1 : 1);
                    }
                    else if (AValues.ColumnValues[ColumnIndex] > BValues.ColumnValues[ColumnIndex])
                    {
                        return(ColumnSortModeAscending ? 1 : -1);
                    }
                }

                return(0);
            }