Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I have a list control on a form view. I am handling LVN_ITEMCHANGED message in form view for various reasons. In a particular case, I want to change the text of a 2nd row, 0th column, so I used setItemText() to do that. At this time, again I am receiving LVN_ITEMCHANGED message, causing a big problem(recursive call).
How can I stop this second message?
Updated 1-Feb-11 4:09am
v2

You could try checking the uChanged parameter of the message as per http://msdn.microsoft.com/en-us/library/bb774845(v=vs.85).aspx[^]
void CMyClass::OnItemChanged(NMHDR *pNMHDR, LRESULT *pResult) {
	*pResult = 1; //or =0 if you want the message to continue to be processed
	pNMLV = (LPNMLISTVIEW)pNMHDR;
	if (!(pNMLV->uChanged & LVIF_TEXT)) {
		//SetItemText();
	}
}


Im not sure if that will work, you may need to experiment with it a little and check the values of pNMLV to see what is changing between the first call and the recursive call.
 
Share this answer
 
Comments
Chris Meech 1-Feb-11 12:15pm    
Good Answer. The ITEMCHANGED message can indicate many different changes. It's important to verify what is actually changing in the handler and react appropriately. It's been awhile since I've looked at list controls, but I doubt that a SetItemText call causes the message. It is more often the result of some user action.
One way to achieve your aims is to have a boolean member ('internalListChange' or similar) set it before your call to setItemText() and reset it after. Then in your message handler, right at the beginning, test for internalListChange = true and return if it is.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900