Search code examples
c++xmlmfcclistctrl

Make single items editable in a list control (C++, MFC)


I have a list control (CListCtrl) with two columns (Name, Value). I add entries dynamically from a xml file. Now i want to make the Value-Column editable and subscribe the Edit-Event to write the changes to the xml. How i do this?

My Code now:

LVITEM item_value;
item_value.iItem = row; 
item_value.iSubItem = 1;
item_value.mask = LVIF_TEXT;
item_value.pszText = value;
ctrl->SetItem(&item_value);

Solution

  • Placing an edit control in CListCtrl is easier by setting the LVS_EDITLABELS style. Use EditLabel() function to place an edit control for a specific item, and retrieve the new text from edit control using GetEditControl() function by listening to the notification LVN_ENDLABELEDIT.