You can sort the ListView (back up a bit, looking for the sort not easy to achieve)

    /// ----------------------------------------------- ------------------------------ /// <summary> list view wrapper. </ Summary> /// <remarks> </ remarks> /// --------------------------------- -------------------------------------------- public class ListViewWrapper {// / <summary> variable to store the icon </ summary> protected ImageList imageList; /// <summary> wrap the subject of the list view control. </ Summary> protected ListView listView; /// --------------------------------------- ----------------------------------------- /// <summary> lap target list reference properties to the view. Is </ summary> /// <value> ListView </ value> /// <remarks> property to publish a reference to the wrapped object control. </ Remarks> /// ----------------------------------------------- --------------------------------- public ListView ListView {get {return listView;}} /// <summary> collection that holds the object list view element. </ Summary> protected Dictionary <int, IObjectListView> dic = new Dictionary <int, IObjectListView> (); /// ------------------------ -------------------------------------------------- --- /// <summary> set of column header. </ Summary> /// <param name = "headersDic"> column header dictionary. </ Param> /// ------------------------------------------- ---------------------------------- public void SetColumnHeaders (SortedDictionary <int, ColumnHeader> headersDic) {ColumnHeader [] array = new ColumnHeader [headersDic.Count]; int index = 0; foreach (ColumnHeader header in headersDic.Values) {array [index] = header; index ++;} this.listView.Columns.AddRange (array);} /// --------------- -------------------------------------------------- --------------- set /// the <summary> /// IObjectListView object list view elements that implement the interface to /// list view. /// </ summary> /// <param name = "list"> IObjectListView </ param> /// <remarks> at the same time as the display value of /// list views, indexes // of the list view to the internal definition dictionary / the value as a key, and set the object list view element. /// </ remarks> /// ---------------------------------------- ---------------------------------------- public void SetObjectList (List <IObjectListView> list) {this.dic.Clear (); this. /// the contents of the internal object list, Items (row record) of the list views that wrap to clear the ///. /// </ remarks> /// ---------------------------------------- ---------------------------------------- public void ClearObjectList () {this.dic. Clear (); this.listView.Items.Clear ();} /// -------------------------------- ------------------------------------------------ // / <summary> /// returns the object list view element that corresponds to the currently selected item. /// </ summary> /// <returns> IObjectListView </ returns> /// <remarks> </ remarks> /// ------------------- -------------------------------------------------- ----------- public IObjectListView GetSelectedObject () {if (this.listView.Items.Count <= 0) {return null; } Int index; try {index = this.listView.SelectedIndices [0];} catch {index = 0;} return dic [(int) this.listView.Items [index] .Tag];} /// --- -------------------------------------------------- --------------------------- /// <summary> /// object list view element that corresponds to the item list that is currently selected It returns a list. /// </ summary> /// <returns> list of IObjectListView </ returns> /// <remarks> </ remarks> /// ----------------- -------------------------------------------------- ------------- public List <IObjectListView> GetSelectedObjectList () {List <IObjectListView> retList = new List <IObjectListView> (); if (this.listView.Items.Count < = 0) {return null;} foreach (int index in this.listView.SelectedIndices) {retList.Add (dic [(int) this.listView.Items [index] .Tag]);} return retList;} /// -------------------------------------------------- --------------------------- /// <summary> constructor. </ Summary> /// <param name = "listView"> lap subject of the list view control. </ Param> /// <remarks> /// lap time to make the setting of the various properties. Multiple row selection can not, all the columns selected at the time of selection, display the /// grid lines, without the automatic sorting, the adoption of detailed display style, but is the default. /// If you change this setting, (at present) this wrapper does not work as intended. /// </ remarks> /// ---------------------------------------- ------------------------------------- public ListViewWrapper (ListView listView) {this.listView = listView;

Reproduced in: https: //my.oschina.net/cjkall/blog/195890

Guess you like

Origin blog.csdn.net/weixin_34391854/article/details/91756231