By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,592 Members | 1,477 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,592 IT Pros & Developers. It's quick & easy.

LVM_SETITEMSTATE

P: n/a
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)

Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.