How to get the selected item of a listview using pure API?
How to get the selected item of a listview using pure API?
If all you have is the windows handle of a listview, how do you get the listview state using Win32 API? No PB commands allowed. Thanks.
This will get the selected index number as well as the selected text, using API only.
Code: Select all
If OpenWindow(0, 0, 0, 300, 140,#PB_Window_SystemMenu | #PB_Window_ScreenCentered, "ListViewGadget") And CreateGadgetList(WindowID(0))
CreateStatusBar(0, WindowID())
hLVG = ListViewGadget(0, 10, 10, 280, 100)
For i = 0 To 9
AddGadgetItem (0, -1, "Test Item " + Str(i))
Next
Repeat
event = WaitWindowEvent()
Select event
Case #PB_EventGadget
Select EventGadgetID()
Case 0
; --> Get index of current ListView selection
lbSel = SendMessage_(hLVG, #LB_GETCURSEL, 0, 0)
; --> Get text length of current selection
lbTextLen = SendMessage_(hLVG, #LB_GETTEXTLEN, lbSel, 0)
; --> Buffer for selected text
lbText$ = Space(lbTextLen1)
; --> Get selected text
SendMessage_(hLVG, #LB_GETTEXT, lbSel, @lbText$)
; --> Display results
StatusBarText(0, 0, "Selected item index (" + Str(lbSel) + ") Selected item text (" + lbText$ + ")")
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1

