Selecting ListView item with Windows Message

K

Koala

Hi, I'm trying to select all listView items with SendMessage API function
and LVM_SETITEMSTATE windows message
....
hWnd = listView.handle;
index = -1;
....
LVITEM lvItem = new LVITEM();
lvItem.mask = LVIF_STATE;
lvItem.stateMask = LVIS_SELECTED;
lvItem.state = LVIS_SELECTED;
IntPtr pointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LVITEM)));
Marshal.StructureToPtr(lvItem, pointer, true);
SendMessage(hWnd, LVM_SETITEMSTATE, index, pointer);
Marshal.FreeHGlobal(pointer);
....
but this code doesn't work as it should...
it selects all items for a short while, but only after I click ListView
control with my mouse which of course move selection to the item I click on
what can be wrong? (please do not suggest other way of selecting items - I
want to do that with LVM_SETITEMSTATE message)
 
M

Morten Wennevik

Hi Koala,

Just a though, is the ListBox set to display selected items when it
doesn't have focus?
 
Joined
Apr 16, 2011
Messages
5
Reaction score
0
Hello Koala, can you help with the source code, i need to select all items in listview too

thanks
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top