View previous topic :: View next topic |
Author |
Message |
nomadjourney
Joined: 16 Dec 2007 Posts: 4
|
Posted: Mon Dec 17, 2007 9:36 am Post subject: ListView sorting question |
|
|
All,
I have a question about sorting ListView columns. I have a ListView which may have a variable number of columns and I wanted to have my code be able to sort whatever column is clicked on. I have a form with code as follows:
Code: |
ListView lv = new dfl.listview.ListView();
with( lv ) {
..
columnClick ~= &lv_ColumnClick;
..
}
protected void lv_ColumnClick( dfl.listview.ListView sender, ColumnClickEventArgs ea ) {
// currentColumn is a class member variable
currentColumn = ea.column;
sender.sorter = &columnSorter;
}
private int columnSorter( dfl.listview.ListViewItem a, dfl.listview.ListViewItem b ) {
return std.string.cmp( a.subItems[ currentColumn ].toString(), b.subItems[ currentColumn ].toString() );
}
|
I record the column number that is clicked before the sort comparison method is called. The sort method is supposed to use the current column number for the comparisons. It works on the first column clicked but not for any subsequent columns. Is there a better (and easier) way to do this and what am I doing wrong? Thanks.
Best regards,
-- Nizam |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Wed Dec 19, 2007 3:06 am Post subject: Re: ListView sorting question |
|
|
It doesn't know you want to re-sort because you're giving it the same sort method. Set the sort method in the constructor and call sort() in the columnClick. |
|
Back to top |
|
|
nomadjourney
Joined: 16 Dec 2007 Posts: 4
|
Posted: Thu Dec 20, 2007 11:12 am Post subject: |
|
|
Thanks Chris. That worked like a champ. |
|
Back to top |
|
|
|