Question

This question is to understand how to update any row programatically. Details. I have a listcrtl, that accepts the data from either from a file or from the edit controls in the dialog. When the items are added I will know its position, that I added, so I can change its subitem texts. I have even implemented the sort functionality in the list, so now the position keeps changing. I have an identifier column for each row, so that I can recognize the row. Now, from an out side event, if I have to change an other columns value of an ID that I know , I have to first find the position of the item by comparing the id column, then with that position, I have set the subitemtext.

This works fine except that it takes time to find the row first then it need to update the column.

Now, in order to get the row directly, I need some help. I have gone through http://msdn.microsoft.com/en-us/library/windows/desktop/hh298346(v=vs.85).aspx But this does not use MFC. Please help me achieving this.

Was it helpful?

Solution

If you have many items you should consider switching to Virtual Lists. It is the fastest way to access the data. If you do not want to invest time to this, then the easiest way for you will be the following:

  1. When you populate the CListCtrl store the ID of each item in the item data using the SetItemData() method. The ID will always be associated with the item, even after re-sorting.
  2. When you need to locate the required item, just scan all items, but do not use GetItemText(). Use GetItemData() instead. This will be faster
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top