How to get the selected item of a listview using pure API?

Everything else that doesn't fall into one of the other PB categories.
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

How to get the selected item of a listview using pure API?

Post by halo »

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.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

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
Post Reply