Re: How to prevent item changed in a CListCtrl?
I was about to suggest using LVN_ITEMCHANGING message instead, that lets you
cancel a change by returning non-zero. But I tested this and it has
Here is my test code:
void CListCtrlDlg::OnLvnItemchangingList1(NMHDR *pNMHDR, LRESULT *pResult)
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
if((pNMLV->uNewState != pNMLV->uOldState) && ((pNMLV->uOldState &
LVIS_SELECTED) == LVIS_SELECTED))
int ret = MessageBox("Do you want to
if (ret == IDCANCEL)
*pResult = 1;
else if (ret == IDYES)
*pResult = 0;
What I saw the if Yes or No was clicked then everything works as expected.
If Cancel is clicked then the same message with the same exact item with the
same exact state gets posted 1 or more times, which results in the dialogbox
coming up again, and once the repeated messages stop both the old item and
new item are selected, as you would have to cancel the selection of the new
item also. I wasn't able to figure out a solution for this.
I can only give you two suggestions, let me edit the item within the list
control using Label Edit. Or you can simply have button that says modify,
and once that is clicked enable your edit controls, and disable your
listcontrol so that they can't change selections until they have saved the
Sorry I couldn't be more help on this.
"Landon" <Landon@discussions.microsoft.com> wrote in message
How to handle if user chose Cancel option? I have been able to handle Yes
No but the problem now is Cancel. I need that if user has made changes in
of the CEdit, and then they change the item selection, if they choose
the focus / selection MUST NOT moved from the current line or in other
How to do that?
I have tried to handle the Yes option only but when I tested it, the
selection still moved to the new item user selected.