FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ListView sorting question

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
nomadjourney



Joined: 16 Dec 2007
Posts: 4

PostPosted: Mon Dec 17, 2007 9:36 am    Post subject: ListView sorting question Reply with quote

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
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Wed Dec 19, 2007 3:06 am    Post subject: Re: ListView sorting question Reply with quote

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
View user's profile Send private message
nomadjourney



Joined: 16 Dec 2007
Posts: 4

PostPosted: Thu Dec 20, 2007 11:12 am    Post subject: Reply with quote

Thanks Chris. That worked like a champ.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group