LVM_SETITEMSTATE

A

Alex Pierson

Trying to select an item from a listview object. Can anyone help?
Here is the code that doesn't work. Note that I have the correct
window and can count the items using LVM_GETITEMCOUNT

Public Const LVM_FIRST As Int32 = &H1000
Public Const LVM_SETITEMSTATE = (LVM_FIRST + 43)
Public Const LVIF_STATE = &H8
Public Const LVIS_SELECTED As Int32 = &H2

Private Const LVM_GETITEMCOUNT = (LVM_FIRST + 4)

Private Const LVM_GETITEMSTATE = (LVM_FIRST + 44)

Public Structure LV_ITEM
Dim Mask As Int32
Dim iItem As Int32
Dim iSubItem As Int32
Dim State As Int32
Dim StateMask As Int32
Dim pszText As Int32
Dim cchTextMax As Int32
Dim iImage As Int32
Dim lParam As Int32
Dim iIndent As Int32
End Structure

Private Declare Function SendMessage Lib "user32.dll" _
Alias "SendMessageW" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByRef lParam As LV_ITEM _
) As Int32

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
Dim h As IntPtr = IntPtr.op_Explicit(&H350818)

Dim i As Integer = SendMessage(h, LVM_GETITEMCOUNT,
IntPtr.Zero, IntPtr.Zero) ' this works with different sendmessage
declaration

Dim li As LV_ITEM
With li
.Mask = LVIF_STATE
' To select item
.State = LVIS_SELECTED
' To deselect item
' .state = 0
.StateMask = LVIS_SELECTED
End With
SendMessage(h, LVM_SETITEMSTATE, 1, li)
 

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