Article ID: 173242 - Last Review: November 21, 2006 - Revision: 2.1 PRB: Use Masks to Set/Get Item States in CListCtrlThis article was previously published under Q173242 On This PageSYMPTOMS
With the CListCtrl class there are no explicit function calls to set or
retrieve the states of the list items. This functionality is handled with
flags or masks. This article explains how to use these masks to get list
items and change their states.
Sample CodeThe following code demonstrates how to select all items in the CListCtrl that begin with the letter "A" and deselect all others. Note that m_listCtrl is a ClassWizard added control data member declared as CListCtrl.MORE INFORMATION
The CListCtrl class supports the GetItemState, SetItemState and GetNextItem
functions. If you use GetNextItem with the appropriate mask, you should be
able to locate the desired list item by its order or its state. To change
the state you would call GetItemState on the item you have located to
obtain the current desired state flag(s), make modifications to the flag(s)
and call SetItemState.
GetNextItemThe GetNextItem function takes two parameters. The first indicates which item (0 based) in the list after which you should begin your search. The current item is excluded from the search. To search the entire list, supply a -1 for this parameter.The second parameter indicates the state that identifies the item for which you are searching. For the CListCtrl, the flags all begin with LVNI_. (see the documentation on CListCtrl::GetNextItem for a complete list). GetItemState, SetItemStateThe GetItemState function will returns a UINT indicating current state flag(s) of the indicated list item. SetItemState accepts a UINT to set the state flag(s) of the indicated list item. Both of these functions take a UINT mask that indicates which of the state flags should be affected.APPLIES TO
| Article Translations
|

Back to the top
