Why is there an LVN_ODSTATECHANGED notification when there's already a perfectly good LVN_ITEMCHANGED notification?

Raymond Chen

If you work with owner-data listviews, you take the responsibility for managing the data associated with each item in the list view. The list view control itself only knows how many items there are; when it needs information about an item, it asks you for it. It’s the fancy name for a “virtual list view” control. When you use an ownerdata list view, you will receive a new notification, LVN_ODSTATECHANGED. The OD stands for ownerdata, so this is an “owner data state changed” notification. The list view sends this notification when the state of one or more items in an owner data list view control change simultaneously. Mind you, the list view control can also send the LVN_ITEMCHANGED notification if the state of an item changes, so you need to be on the lookout for both. If there is a notification LVN_ITEMCHANGED, then what’s the purpose of the LVN_ODSTATECHANGED message? It’s redundant, after all.

Well yes, it’s redundant, but it’s faster, too. The LVN_ODSTATECHANGED notification tells you that the state of all items in the specified range has changed. It’s a shorthand for sending an individual LVN_ITEMCHANGED for all items in the range [iFrom..iTo]. If you have an ownerdata list view with 500,000 items and somebody does a select-all, you’ll be glad that you get a single LVN_ODSTATECHANGED notification with iFrom=0 and iTo=499999 instead of a half million individual little LVN_ITEMCHANGED notifications.

0 comments

Discussion is closed.

Feedback usabilla icon