Selecting ListView item with Windows Message

  • Thread starter Thread starter Koala
  • Start date Start date
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)
 
Hi Koala,

Just a though, is the ListBox set to display selected items when it
doesn't have focus?
 
Hello Koala, can you help with the source code, i need to select all items in listview too

thanks
 
Last edited:
Back
Top