sorting in listview using vb.net 2008? -
how sort data in listview using vb.net 2008 without using listview1_columnclick ?
here's code , doesn't sort properly.
if listview1.sorting = sortorder.ascending listview1.sorting = sortorder.descending else listview1.sorting = sortorder.ascending end if
many reply.
-jane
you need tell listview how sorting.
in c#:
create comparer:
// implements manual sorting of items columns. class listviewitemcomparer : icomparer { private int col; public listviewitemcomparer() { col = 0; } public listviewitemcomparer(int column) { col = column; } public int compare(object x, object y) { return string.compare(((listviewitem)x).subitems[col].text, ((listviewitem)y).subitems[col].text); } }
and invoke sorting calling:
this.listview1.listviewitemsorter = new listviewitemcomparer(colnum);
where colnum index of column want sort.
example taken here: http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.columnclick.aspx
and here's solution in vb.net:
create comparer:
' implements manual sorting of items columns. class listviewitemcomparer implements icomparer private col integer public sub new() col = 0 end sub public sub new(byval column integer) col = column end sub public function compare(byval x object, byval y object) integer _ implements icomparer.compare return [string].compare(ctype(x, listviewitem).subitems(col).text, ctype(y, listviewitem).subitems(col).text) end function end class
and invoke sorting calling:
me.listview1.listviewitemsorter = new listviewitemcomparer(colnum)
where colnum index of column want sort.
Comments
Post a Comment