Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LVN_ITEMCHANGED handler called 3 times instead of one

0 views
Skip to first unread message

Aleksandar Pu$ka$

unread,
Jul 14, 1998, 3:00:00 AM7/14/98
to
In my app I have CListCtrl derived class (ownerdrawn). It's set to be
single-selection, report style. I use ClassWizard to create a handler
for the LVN_ITEMCHANGED notification message. When control contains
some rows and I try to change a selection my handler gets called 3
times!!!

In the handler I do an AfxMessgeBox and print the current selection.
First time it's the previous selection. The second it's -1(no
selection) and finally the third it's the new selection. I've found a
way to get around two extra (useless) calls but can't escape the
feeling that I'm doing something wrong. It seems too silly for this to
be a behaviour by design.

Any comments?!

--
Alex.
gu...@cyberdude.com

Tony Hoyle

unread,
Jul 14, 1998, 3:00:00 AM7/14/98
to

This is by design:

The first notification says that the previous item has been deselected
The second notification says that the new item has been selected

Not sure why you get three though, although it may be notification of
focus change.

You should examine the NMLISTVIEW structure to find out what has
changed, and only change the selection if the LVIS_SELECTED bit has
been set.

Tony

-----------------------------------------------------------------------------
Home: (+44) 161 737 0008 Work: (+44) 161 278 2463
Email:t...@netfusion.co.uk <><
ICQ: 13746312

Homepage: http://sale.netfusion.co.uk (Last update 24/6/98)
-----------------------------------------------------------------------------


Victor Levy

unread,
Jul 16, 1998, 3:00:00 AM7/16/98
to
Aleksandar,
 
>You should examine the NMLISTVIEW structure to find out what has
>changed, and only change the selection if the LVIS_SELECTED bit has
>been set.
 
Tony's right, mostly.  Actually, the LVIS_SELECTED bit is set only if the item is selected.  What you want to know is whether the item's selection has changed.  This is how our code checks this:
 
afx_msg void   CDerivedList::OnItemChanged (
            NMHDR*   a_pNotifyStruct,
            LRESULT*)
{
   NM_LISTVIEW
     *pListViewNotify = (NM_LISTVIEW *) a_pNotifyStruct;
   ASSERT (a_pNotifyStruct -> code == LVN_ITEMCHANGED);
   Default ();
   if (pListViewNotify -> uChanged & LVIF_STATE) {
      /*
      %------------------------------%
      % Process the selection change %
      %------------------------------%
      ...
      }
 
Hope this helps, Vic
--
Victor Levy
Columbia Scientific, Inc.
South Bend, Indiana, USA
 
XXv...@skeyenet.netXX    <- Remove XXs for correct address
Tony Hoyle wrote in message <35ab3f93.596915699@news>...

Aleksandar Pu$ka$

unread,
Jul 17, 1998, 3:00:00 AM7/17/98
to
Thanks to both of you! It is so obvious. I don't know how I could have
been so blind ;)
Thanks again!

--
Alex.
--

0 new messages