成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

怎樣對ListView中的內容排序?

2010-08-28 10:50:01來源:西部e網作者:

The .NET Compact Framework does not support the ListView.Sort method, but you can still sort items. This QuickStart defines an implementation of the IComparable interface to use with the ArrayList.Sort method.

The following screen shot shows items sorted, in descending order, by the Sales column. Note that sales figures under 1000 require padded zeros to sort correctly.

ListView sorted by the third column

Defined Classes

The following table describes the classes defined in this QuickStart.

Class Description
ColHeader Derived from the ColumnHeader class, this class is used for adding columns to the ListView control and for sorting the clicked column. It includes a Boolean property, ascending, to specify the direction of the sort: true specifies ascending and false specifies descending.
SortWrapper When a column is clicked, an instance of this class is created for each ListItem and added to an ArrayList. Each wrapped item includes a property containing the index of the clicked column. This class contains the SortComparer class.
SortComparer Contains an implementation of the IComparer interface whose Compare method compares objects, two at a time, as the ArrayList is sorted.

Performing the sort

The event handler for the ColumnClick event performs the sort operation as follows:

  1. Creates an instance of the ColHeader class for determining which column is clicked.
  2. Sets the ascending property of the ColHeader object to sort in the opposite direction.
  3. Gets the number of items in the list.
  4. Disables drawing the display during the sort with the BeginUpdate method.
  5. Adds a SortWrapper for each ListView item to an ArrayList.
  6. Sorts the elements in the ArrayList using a new instance of the SortComparer class whose implementation of the IComparer interface contains the logic of the sort in its Compare method.
  7. Clears the ListView control of items and repopulates the control with the sorted items from the ArrayList.
  8. Enables drawing the display with the EndUpdate method.

Note that the ArrayList.Sort method in this QuickStart performs an unstable sort; that is, if two elements are equal, their order might not be preserved. In contrast, a stable sort preserves the order of elements that are equal.

關鍵詞:VS.NET
主站蜘蛛池模板: 安康市| 缙云县| 唐海县| 郴州市| 安庆市| 镇赉县| 定安县| 通渭县| 沂南县| 于田县| 盐源县| 竹山县| 大渡口区| 叙永县| 曲阜市| 慈利县| 寻甸| 宁明县| 桦南县| 酉阳| 广灵县| 敦煌市| 洞口县| 新干县| 新安县| 富蕴县| 德惠市| 蕲春县| 阳新县| 建水县| 梁平县| 民县| 呼和浩特市| 绥阳县| 农安县| 靖安县| 贵南县| 韶山市| 陕西省| 南溪县| 马公市|