/// <summary> /// Initializes a new instance of the <see cref="ListViewItemSorter"/> class /// that uses the specified comparers to sort columns /// and attaches the new instance to the specified ListView. /// </summary> /// <param name="listView">The ListView that should be sorted and monitored for column click events.</param> /// <param name="itemComparers">An array of objects that implement IListViewItemComparer. /// The index of the comparer in the array corresponds to the index of the list view column that it sorts. /// If an element is <c>null</c>, the corresponding column cannot be sorted. /// If this parameter is <c>null</c>, all columns can be sorted by their text content.</param> /// <remarks> /// Note that the ListViewItemSorter constructor adds two bitmaps to the /// SmallImageList of the ListView (an empty ImageList will be created /// first if none is assigned). /// </remarks> public ListViewItemSorter(ListView listView, IListViewItemComparer[] itemComparers) { if (listView == null) { throw new ArgumentNullException("listView"); } this.listView = listView; if (itemComparers == null) { IListViewItemComparer defaultComparer = new ListViewTextColumnComparer(); this.itemComparers = new IListViewItemComparer[this.ListView.Columns.Count]; for (int i = 0; i < this.itemComparers.Length; i++) { this.itemComparers[i] = defaultComparer; } } else { this.itemComparers = itemComparers; } if (this.ListView.SmallImageList == null) { this.ListView.SmallImageList = new ImageList(); } this.ListView.SmallImageList.Images.Add("SortAscending", BitmapResources.GetBitmap("Icons.16x16.SortAscending.png")); this.ListView.SmallImageList.Images.Add("SortDescending", BitmapResources.GetBitmap("Icons.16x16.SortDescending.png")); this.ListView.ColumnClick += this.ListViewColumnClick; this.ListView.ListViewItemSorter = this; }
public ResourceList(ResourceEditorControl editor) { undoStack = new UndoStack(); name.Text = ResourceService.GetString("Global.Name"); name.Width = 250; type.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.TypeColumn"); type.Width = 170; content.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.ContentColumn"); content.Width = 300; Columns.AddRange(new ColumnHeader[] {name, type, content}); FullRowSelect = true; AutoArrange = true; Alignment = ListViewAlignment.Left; View = View.Details; GridLines = true; LabelEdit = true; Dock = DockStyle.Fill; HideSelection = false; BorderStyle = System.Windows.Forms.BorderStyle.None; images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.string")); images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.bmp")); images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.icon")); images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.cursor")); images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.bin")); images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.obj")); SmallImageList = images; // Set up sorting: // User can sort the list by name and by type, // whereas sorting by type also implicitly sorts by name. IListViewItemComparer textComparer = new ListViewTextColumnComparer(); IListViewItemComparer typeNameComparer = new ListViewMultipleColumnsComparer(textComparer, 1, textComparer, 0); sorter = new ListViewItemSorter(this, new IListViewItemComparer[] { textComparer, typeNameComparer, null }); sorter.SortColumnIndex = 0; sorter.SortOrder = SortOrder.Ascending; ContextMenuStrip = MenuService.CreateContextMenu(editor, "/SharpDevelop/ResourceEditor/ResourceList/ContextMenu"); }
/// <summary> /// Initializes a new instance of the <see cref="ListViewItemSorter"/> class /// that uses the specified comparers to sort columns /// and attaches the new instance to the specified ListView. /// </summary> /// <param name="listView">The ListView that should be sorted and monitored for column click events.</param> /// <param name="itemComparers">An array of objects that implement IListViewItemComparer. /// The index of the comparer in the array corresponds to the index of the list view column that it sorts. /// If an element is <c>null</c>, the corresponding column cannot be sorted. /// If this parameter is <c>null</c>, all columns can be sorted by their text content.</param> /// <remarks> /// Note that the ListViewItemSorter constructor adds two bitmaps to the /// SmallImageList of the ListView (an empty ImageList will be created /// first if none is assigned). /// </remarks> public ListViewItemSorter(ListView listView, IListViewItemComparer[] itemComparers) { if (listView == null) { throw new ArgumentNullException("listView"); } this.listView = listView; if (itemComparers == null) { IListViewItemComparer defaultComparer = new ListViewTextColumnComparer(); this.itemComparers = new IListViewItemComparer[this.ListView.Columns.Count]; for (int i = 0; i < this.itemComparers.Length; i++) { this.itemComparers[i] = defaultComparer; } } else { this.itemComparers = itemComparers; } if (this.ListView.SmallImageList == null) { this.ListView.SmallImageList = new ImageList(); } this.ListView.SmallImageList.Images.Add("SortAscending", BitmapResources.GetBitmap("Icons.16x16.SortAscending.png")); this.ListView.SmallImageList.Images.Add("SortDescending", BitmapResources.GetBitmap("Icons.16x16.SortDescending.png")); this.ListView.ColumnClick += this.ListViewColumnClick; this.ListView.ListViewItemSorter = this; }