Home All Groups Group Topic Archive Search About

Selecting ListView item with Windows Message

Author
26 Nov 2004 4:40 PM
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)

Author
26 Nov 2004 7:04 PM
Morten Wennevik
Hi Koala,

Just a though, is the ListBox set to display selected items when it 
doesn't have focus?

--
Happy Coding!
Morten Wennevik [C# MVP]
Author
26 Nov 2004 7:30 PM
Koala
> Just a though, is the ListBox set to display selected items when it 
> doesn't have focus?

HideSelection is the answer! THX! :))

AddThis Social Bookmark Button