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

ListView gets LVN_ITEMCHANGED after sending LVM_SETITEMSTATE

461 views
Skip to first unread message

Todor Todorov

unread,
Aug 10, 2002, 8:07:01 PM8/10/02
to
I am developing an application in Smalltalk that uses ListViews. But I have
come across an annoying thing with the LVN_ITEMCHANGED notification. Here is
the situation. I send a LVM_SETITEMSTATE message to set the state of a
particular item to LVIS_SELECTED | LVIS_FOCUSED. This of course selects the
new item, but I get LVN_ITEMCHANGED notification back in my face. This
triggers a change event that updates the application with the new list
selection - which is unnecessary, since it was the application that set the
selection moments ago.

Is there a way to tell that it was me (the application) that caused the
LVN_ITEMCHANGED by sending LVM_SETITEMSTATE? Does the MFC CListView receive
events when it changes the selection of the list view? Has anybody a
solution to this problem?

Thanks!

-- Todor Todorov

David Lowndes

unread,
Aug 11, 2002, 5:02:36 AM8/11/02
to
>Is there a way to tell that it was me (the application) that caused the
>LVN_ITEMCHANGED by sending LVM_SETITEMSTATE?

Set a flag so you know it's you.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.

Luki de Silva

unread,
Aug 12, 2002, 12:37:52 AM8/12/02
to
Hi Todor,

This is easy! The 'lParam' value in the LVN_ITEMCHANGED notification points
to a NMLISTVIEW structure. You can check the 'uChanged' member of this
structure to identify what attributes have changed in an item. If you want
to ignore the LVN_ITEMCHANGED notifications generated when an item's state
has changed (i.e. when an item selected or focus has changed) ... check if
the LVIF_STATE bit is set in the 'uChanged' member.

As for your 2nd query, yes MFC recieves ALL the notifications (i.e. events)
for any common control including the list view control. MFC control classes
like CListCtrl are just wrapper classes around their common control
counterparts. Refer to the ON_NOTIFY( ) message map handling macro on how
to trap control notifications within MFC.

Cheers,
Luki


"Todor Todorov" <t...@cdm.dk> wrote in message
news:OrJxZrMQCHA.4328@tkmsftngp13...

Christian McArdle

unread,
Aug 13, 2002, 6:41:28 AM8/13/02
to
>Is there a way to tell that it was me (the application) that caused the
>LVN_ITEMCHANGED by sending LVM_SETITEMSTATE? Does the MFC CListView receive
>events when it changes the selection of the list view? Has anybody a
>solution to this problem?

This is an annoying design "feature" from Microsoft. You need to have an
"ignore notifications" flag, which you can set when you send a message to
the control. You then just discard any notifications that happen when the
flag is set.

Christian.

Todor Todorov

unread,
Aug 14, 2002, 12:41:17 AM8/14/02
to
Thanks to all :-)

"Christian McArdle" <cmcar...@nospam.yahooxxxx.co.uk> wrote in message
news:3d58e258$0$236$ed9e...@reading.news.pipex.net...

0 new messages