The information in this article applies to:
SUMMARYSelecting a listview item is not as easy as selecting a list box item was in Windows version 3.1. To select a list box item, an application sends an LB_SETCURSEL or LB_SETSEL to a single- or multiple-selection list box respectively. To select a listview item, an application sends an LVM_SETITEMSTATE message or calls the ListView_SetItemState() macro. MORE INFORMATION
An application can force a selection of a listview item. You might want the
application to do this when a user clicks a column other than the first
column of a listview of multiple subitems or columns.
Note that the last parameter passed to this macro is a mask specifying
which bits are about to change. LVIS_FOCUSED and LVIS_SELECTED are defined
in <commctrl.h> as 0x0001 and 0x0002 respectively, so you need to set the
last four bits of the mask.
The same principle applies to selecting a treeview item programmatically. The only difference is that an application sends a TVM_SETITEM message or calls the TreeView_SetItem() macro. Because listviews allow multiple selection by default, you can program an application to select multiple items by simulating a CTRL keydown (or SHIFT keydown event) prior to setting the item state. For example, the following code simulates the pressing of the CTRL key:
Note that if an application simulates a keypress, it must also be
responsible for releasing it by resetting the appropriate bit. For example,
the following code simulates the release of a CTRL key:
Similarly, retrieving the currently selected item in a listview control
in Windows is not as easy as sending an LB_GETCURSEL message to a
listbox control.
For listviews, call the ListView_GetNextItem() function with the LVNI_SELECTED flag specified:
For treeviews, retrieve the currently selected item by calling the
TreeView_GetNextItem() function with the TVGN_CARET flag
specified or by calling the TreeView_GetSelection() macro directly:
or
Additional query words:
Keywords : kbcode kbCtrl kbListView kbNTOS kbWinOS2000 kbSDKWin32 kbGrpUser kbWinOS95 kbWinOS98 |
Last Reviewed: February 2, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |