About ListView Sort by other non-default columns:

zhaozj2021-02-16  67

As described below:

INTERNAL CLASS LISTVIEWITEMCOMPARER: IComparer

{

Private int co1;

Private sortorder order;

Public ListViewItemComparer ()

{

COL = 0;

ORDER = Sortorder.ascending;

}

Public ListViewItemComparer (int Column, Sortorder Order)

{

COL = column;

THIS.Order = ORDER;

}

Public Int Compare (Object X, Object Y)

{

Int retURNVAL = -1;

IF ((ListViewItem) x). Subitems.count> Col ​​&& ((listviewItem) Y) .SUBITEMS.COUNT> COL)

{

Returnval = string.Compare ((ListViewItem) x) .subitems [col] .text,

(ListViewItem) Y) .SUBITEMS [col] .text);

IF (ORDER == Sortorder.Descending)

ReturnVal * = -1;

}

Return ReturnVal;

}

}

Call: The first parameter is the sort field, the second parameter is sorted mode (ascending, descending)

This.getCurrentlist (). ListviewItemsORTER = New ListViewItemComparer (2, this.getcurrentlist (). sorting);

THIS.GETCURRENTLIST (). sort ();

转载请注明原文地址:https://www.9cbs.com/read-15357.html

New Post(0)