473,412 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Help Sorting CListCtrl

464 Expert 256MB
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 5648
Studlyami
464 Expert 256MB
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
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...
2
by: Chandrakanth | last post by:
How to make the selection in CListCtrl to appear in different color?
2
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 ...
2
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...
0
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...
0
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...
0
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...
1
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====================...
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.