Click to See Complete Forum and Search --> : I get multiple LVN_ITEMCAHNGED notifications in CListCtrl derived class


raza
September 12th, 1999, 09:02 AM
I want to do something on every change of selection-set in a multi-select CListCtrl. I am handling the LVN_ITEMCHANGED notification but I get multiple LVN_ITEMCAHNGED notifications. I have been able to get help from the documentation. Which member of the NM_LISTVIEW do I need to use to filter amongst the multiple messages? Or is there another way to determine the selection change once?

Thanks in advance.

Luis Teixeira
September 27th, 1999, 05:59 AM
Hi!
I guess we are both solving the same problem. I can't find anything on Microsoft's documentation.It seems that we get a LVN_ITEMCHANGED notification everytime an item's state changes. Now, if you have a selected set of items and you want to change it to a different set of items you'll get the LVN_ITEMCHANGED notification messages for both the deselection and the selection. Now my code doesn´t work like i want it to work, but have you tried to verify the uOldState/uNewState of the NM_LISTVIEW structure and compare it with LVIS_SELECTED?
I'm using these NM_LISTVIEW members combined with the uChanged member.Like:

//Check for state changes
if(pNMListView->uChanged==LVIF_STATE)
{
//Is it selected?
if(pNMListView->uNewState==LVIS_SELECTED)
{
......
}
//Was it selected?
if(pNMListView->uOldState==LVIS_SELECTED)
{
......
}
}




Depending on what you want to do, this approach might help you. It almost helped me.
Let me know if it did or not.
Bye and good luck.

Luís Teixeira

Weiye
January 5th, 2002, 11:47 PM
I also have the same problem and this is what i found out.// When you first select an item in the list control
pNMListView->uNewState == LVIS_FOCUSED | LVIS_SELECTED;

/* --- Later when you select another item onwards, 3 selection changed notifications are sent --- */

// First notification
pNMListView->uNewState == 0;
pNMListView->uOldState == LVIS_FOCUSED;

// Second notofication
pNMListView->uNewState == 0;
pNMListView->uOldState == LVIS_SELECTED;

// Third notification
pNMListView->uNewState == LVIS_FOCUSED | LVIS_SELECTED;
pNMListView->uOldState == 0;

As a result, i did this on LVN_ITEMCHANGED to filter off those unneeded notifications// Check if item changed
if (pNMListView->uNewState == (LVIS_FOCUSED | LVIS_SELECTED) && pNMListView->uOldState == 0)
{
// Do my stuff
}



Chen Weiye
------------------------------------------------------------------------------
When pursuing your dream, don't forget to enjoy your life...
------------------------------------------------------------------------------