From: N. Karademir on 14 Sep 2005 12:22 Hi, i am new to vc i have a clistctrl report=view sort = none owner data = false owner data fix = false i just want to click on a button and sort all items onbutton1() { //ascending sort ... m_List1.SortItems() // or whatever } can someone show me real working code? iam trying out for days now. thanks, N. Karademir Smart Software
From: Joseph M. Newcomer on 14 Sep 2005 11:52 Sorting a list control is a bit obscure, for reasons that escape most of us. It turns out that unlike a listbox, where you get useful stuff in the compare handler, in a list control you get only the LPARAM information (the "itemData"). Unfortunately my working code is very domain-specific and I can't really show it, because it wouldn't help much. What I've done is put into the LPARAM a pointer to an object that I use to sort. Most often this is a struct whose contents are reflected in the columns of the list control. So a file object would have an associated struct that had the filename, date, time, etc. When I sort, I get a pointer to this struct. Based on what I'm sorting on, I'll compare the fields of the two structs whose pointers I have available. Note that the compare algorithm gets two LPARAM values, which you must cast to pointers (and if you are using VS.NET, note the type of LPARAM *could* be 64 bits!). Another approach I've take is to compute the LPARAM only "on demand", that is, I do something like: c_MyListControl.PrepSort(); c_MyListControl.SortItems(); c_MyListControl.UnprepSort(); where PrepSort might take an argument saying what to sort on, and fills in the LPARAM with a pointer (for example, my sort handler might work on strings, and my PrepSort, if I'm sorting on date, would create a string of a fixed number of digits with leading zeroes that represents the timestamp), SortItems will call my sort routine, and UnprepSort will free up all the LPARAM values I created in order to do the sort. Lest you think this is inefficient, be aware that even for list controls with a fairly large number of entries (several thousand), this whole operation takes place while forebrain is still processing the notification that the button has clicked, so the delays are masked by human reaction time. More time is spent redrawing the sorted image than is spent sorting the data. joe On Wed, 14 Sep 2005 16:22:50 -0000, "N. Karademir" <n.karademir(a)smart-software.org> wrote: >Hi, > >i am new to vc > >i have a clistctrl >report=view >sort = none >owner data = false >owner data fix = false > >i just want to click on a button and sort all items > >onbutton1() >{ > //ascending sort ... > m_List1.SortItems() // or whatever >} > >can someone show me real working code? >iam trying out for days now. > >thanks, > >N. Karademir >Smart Software > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: "CheckAbdoul" <checkabdoul at mvps dot on 14 Sep 2005 14:13 Take a look at the following KB article How To Sort Items in a CListCtrl in Report View http://support.microsoft.com/?id=250614 -- Cheers Check Abdoul [VC++ MVP] ----------------------------------- "N. Karademir" <n.karademir(a)smart-software.org> wrote in message news:O08IbhTuFHA.3424(a)tk2msftngp13.phx.gbl... > Hi, > > i am new to vc > > i have a clistctrl > report=view > sort = none > owner data = false > owner data fix = false > > i just want to click on a button and sort all items > > onbutton1() > { > //ascending sort ... > m_List1.SortItems() // or whatever > } > > can someone show me real working code? > iam trying out for days now. > > thanks, > > N. Karademir > Smart Software > >
|
Pages: 1 Prev: 'GetDefaultPrinter' : undeclared identifier. Next: how to compile emule source code? |