A list view control has to have the LVS_EDITLABELS style for it to be editable. This style can be set when creating the control or even later by using ModifyStyle(). Once we have set the LVS_EDITLABELS style, the user can set focus on an item and click on it again to begin editing the item. However, the default behaviour of the control ignores the changes once the edit is complete. To allow the edit changes to be accepted, we have to add a handler to the LVN_ENDLABELEDIT notification. Here is a sample of a reflected message handler (e.i. the message is handled by the list view control itself, rather than the parent window).void CMyListCtrl::OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult) { *pResult = TRUE; }If we set *pLResult to FALSE, the changes are ignored. Allowing edits of sub items are not directly supported by the control but can be easily implemented. It is covered in a different section. ============Normally an edit is initiated when a user clicks on an item that already has the focus. Suppose, you want to start the edit when the user clicks a button, here is the code to start the edit.m_listctrl.SetFocus(); m_listctrl.EditLabel(nItem);You should remember to SetFocus() if the listview control does not already have the focus. Of course, for this to work, the listview control should have the LVM_EDITLABEL style.
CListCtrl要做成可编辑的,也是挺容易的事情。不需要派生子类来完成。
This style can be set when creating the control or even later by using ModifyStyle().
Once we have set the LVS_EDITLABELS style, the user can set focus on an item and click on it again to begin editing the item.
However, the default behaviour of the control ignores the changes once the edit is complete.
To allow the edit changes to be accepted, we have to add a handler to the LVN_ENDLABELEDIT notification.
Here is a sample of a reflected message handler (e.i. the message is handled by the list view control itself,
rather than the parent window).void CMyListCtrl::OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = TRUE;
}If we set *pLResult to FALSE, the changes are ignored. Allowing edits of sub items are not directly supported
by the control but can be easily implemented. It is covered in a different section. ============Normally an edit is initiated when a user clicks on an item that already has the focus.
Suppose, you want to start the edit when the user clicks a button, here is the code to start the edit.m_listctrl.SetFocus();
m_listctrl.EditLabel(nItem);You should remember to SetFocus() if the listview control does not already have the focus.
Of course, for this to work, the listview control should have the LVM_EDITLABEL style.
看一下这个例子