473,786 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help Sorting CListCtrl

464 Recognized Expert Contributor
Alright, I have a list which is constantly getting items added and items removed. I want the user to be able to click the header of the list control and sort the items by the column clicked. Ive searched around and the best description i could fine is this. Now here is what i have.

I have captured the user clicking on the header and i have the column in which the user clicked. I have a feeling its how I'm entering data into the list specifically the SetItemData, or the container that I'm using isn't supported for what the program is doing.

Header
Expand|Select|Wrap|Line Numbers
  1. typedef struct 
  2. {
  3. LPTSTR Name;
  4. LPTSTR Age;
  5. LPTSTR Location;
  6. } ITEMDATA, *PITEMDATA;
  7. ...
  8. vector<ITEMDATA> MyVector;
  9.  
  10.  
Code File
*Note MyClass contains the same data elements + like 20 other elements which isn't shown on the list
Expand|Select|Wrap|Line Numbers
  1. void InsertListItem(MyClass MyClassObject)
  2. {
  3.  
  4.      ITEMDATA TempData;
  5.      TempData.Name = MyClassObject.Name;  
  6.      TempData.Name = MyClassObject.Age;
  7.      TempData.Name = MyClassObject.Location;
  8.  
  9.      MyVector.push_back(TempData); //Im not sure if assigning the values that way is the proper also
  10.  
  11.      int max = m_list.GetRowCount(); //m_list is the list control Object
  12.  
  13.      m_list.InsertItem(max, MyClassObject.Name);
  14.      m_list.InsertItemText(max, 1, MyClassObject.Age);
  15.      m_list.InsertItemText(max, 2, MyClassObject.Location);
  16.      m_list.SetItemData(max, (LPARAM) &MyVector[MyVector.size()-1]);//i don't know if thats right
  17. }
  18.  
The Handler
Expand|Select|Wrap|Line Numbers
  1. void CEOB::OnHdnItemclickList(NMHDR *pNMHDR, LRESULT *pResult)
  2. {
  3.  
  4.    NMLISTVIEW *pLV = (NMLISTVIEW *) pNMHDR;
  5.  
  6.     m_list.SortItems(SortFunc, pLV->iItem); //iItem = column clicked
  7.     //.SortItems(SortFunc, pLV->iItem);
  8.  
  9.     *pResult = 0;
  10. }
  11.  
  12. int CALLBACK SortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  13. {
  14.     int nRetVal;
  15.  
  16.     PITEMDATA pData1 = (PITEMDATA)lParam1; //PData1 = bat ptr
  17.     PITEMDATA pData2 = (PITEMDATA)lParam2; // same as above
  18.     ...
  19.  
I'm lost in what to do. The SetItemData is supose to set up the Lparam of the List item, so im guessing my SetItemData isn't working properly. Any help is appricated. I'm also open for other sujestions on how to handle sorting.
Oct 3 '07 #1
1 5667
Studlyami
464 Recognized Expert Contributor
Okay after another long search and many different tries I found this article . I followed this example which looks up the list item based on lparam and now it works fine. It turns out that the MSDN code was wrong (at least that what was stated on a several different articles).
Oct 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4102
by: Joseph Smith | last post by:
Well I just started playing with VC++ yesterday, so keep it simple if you can. thx. Anyway, I'm having problems with a CListCtrl in report view. The first column seems to display fine, but the other columns don't. Have a look at my function for adding data: void CMP3RenamerDlg::PopulateList(CString str) { CFileFind finder;
2
2159
by: Chandrakanth | last post by:
How to make the selection in CListCtrl to appear in different color?
2
2203
by: Geo | last post by:
Hi, I'm using a List Control (report view) in a dialog. This list displays 4 text items, each consisting of 3 columns. Let's consider the following example: Title of column1 Title c2 Title c3 Title c4 Item1 info12 info13 info14 Item2 info22 info23 info24 Item3 info32 info33 info34
2
4199
by: Herbert VON GRÜNENWALD | last post by:
Hi everyone ! I would like to set an ListViewItem at a special position, into a ListView. There is Bounds, but it's a propertie, that can be only get ! (i could to that in MFC with CListCtrl.SetItemPosition(...)) thanks
0
1937
by: Rajko | last post by:
Here is something I find unusual. I implemented Drag and Drop to CListCtrl. First I created my own class myCListCtrl from CListCtrl. I implemented OnMouseMove and OnLButtonUp message handlers in class. Unusual : If I don't use RedrawWindow() I get trails from m_dragImage. and second thing is I don't need to use DragShowNolock(FALSE) and DragShowNolock(TRUE) to
0
1884
by: Ryan Albarelli | last post by:
Here's one I've spent the last 6 hours trying to figure out... I have a CListCtrl derived class. The first time I click an item in the list to select it, I see a lot of multimedia dll's being loaded and unloaded causing a noticable delay before the item selects. After that its fine. The funny thing is, my set up is exactly the same as another program I have and it doesn't load anything! I created a stock MFC DLG app with a CListCtrl...
0
2277
by: Victor | last post by:
Hi everybody! VS.NET 2003 C++ MFC project for Windows XP I would like to use a CListCtrl control in a dialog. So I have #include'd "afxcmn.h" in my CMyDialog.h and declared a variable CListCtrl list; This compiles fine. But now I try to invoke a function list.SetView(0). The compiler says : 'SetView' is not a member of the CListCtrl. I inquired into the afxcmn.h and found that this function is only
1
1213
by: rxgmoral | last post by:
dll problem,help me:) i create dll project ,the dll is Use MFC in a Static Library i hope exe call ListCtrl class from dll ==================DLL==================== <<<<<<<<<<ListCtrl.h>>>>>>>>>>>>>>> #pragma once class AFX_EXT_CLASS ListCtrl :public CListCtrl { public:
1
6628
by: rag84dec | last post by:
Hi, I have many check boxes in a list control.My problem is to uncheck the check box if there is a check box already checked.How can i do??..I tried doing the below but it checks the first check box and unchecks the others. void SomeClass::OnCheckboxChanged ( NMHDR* pNMHeader, LRESULT* pResult ) { func(); }
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.