-
ListView SetCheck
How do you I set the check mark checked with the SendMessage? I saw on a previous board that there is ListView_SetCheckState, but I searched the <commctrl.h> and it didn't find that macro.
I got this so far:
Code:
void SetItemChecked(HWND hwnd, int index)
{
LVITEM lvItem;
lvItem.mask=LVIF_STATE;
// lvItem.state= //stuck here
SendMessage(hwnd, LVM_SETITEMSTATE, (WPARAM) (int)index, (LPARAM) (LPLVITEM)lvItem);
}
The constants I found were:
LVIS_ACTIVATING
The item is being activated in an LVN_ITEMACTIVATE notification.
LVIS_CUT
The item is marked for a cut-and-paste operation.
LVIS_DROPHILITED
The item is highlighted as a drag-and-drop target.
LVIS_FOCUSED
The item has the focus, so it is surrounded by a standard focus rectangle. Although more than one item may be selected, only one item can have the focus.
LVIS_SELECTED
The item is selected. The appearance of a selected item depends on whether it has the focus and also on the system colors used for selection.
I don't know what constant to enter here. Or if I have to fill out more fields. Any help would be really be appriated.
Thanks.
-
The easiest way is to use the ListView_SetCheckState macro documented at msdn:
ListView_SetCheckState
For such problems you should first search at msdn - mostly you find the answer fast.
Greetz
Andy
-
I would use ListView_SetCheck but when I do, the compiler says that it doesn't exist. So I went to commctrl.h so search for it, but it didn't find it. Thats why I wanted another way of setting the check.
Thanks.
-
I figured it out...finially :)
Code:
void SetItemChecked(HWND hwnd, int index)
{
LVITEM lvItem;
lvItem.stateMask=LVIS_STATEIMAGEMASK;
lvItem.state=INDEXTOSTATEIMAGEMASK(2);
SendMessage(this->hwnd, LVM_SETITEMSTATE, index, (LPARAM)&lvItem);
}
lvItem.state=INDEXTOSTATEIMAGEMASK(2);
2 means the box will be checked
1 means the box will be unchekced
0 means there won't be a box