problems multiselecting listview gadget

Just starting out? Need help? Post your questions and find answers here.
wolfwood2x
User
User
Posts: 76
Joined: Sun Oct 02, 2005 5:08 am

problems multiselecting listview gadget

Post by wolfwood2x »

Hey guys. I am having trouble returning the value of multiple items that are selected in a list view gadget. I set coded this to spike out the listview gadget and it does not appear to function as I had thought after reading the description of it in the help file.

Code: Select all

index=GetGadgetState(#list)
    If index <> (-1)
        Debug index
        GetGadgetItemText(#list, index, 0)
        SetGadgetItemState(#list, index, 0)
        index=0
        Debug index
        index=GetGadgetState(#list)
        Debug index
    EndIf
What I am trying to do is select 2 or more items in the listview and cycle through them. I need to get the values of the selected items. I tried to check whether or not an item was selected by the first assignment of index. Then it spits out the numerical value of index and tries to get the text out at that position. Next I de-select the original item. Now here is the first big issue. When I de-select it, it does in fact de-select the item at index. However, if I try to do another check for the next selected item at the next assignment statement for index it returns the original value which should have been de-selected and currently shows up as de-selected in the gadget. How can you loop through these items?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hi, not really sure what you're after so I'm not sure if the following will help :

Code: Select all

 If OpenWindow(0, 0, 0, 270, 250, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    ListViewGadget(0, 10, 10, 250, 120, #PB_ListView_Multiselect)
    ButtonGadget(1, 10, 150, 100, 30, "List selected items.")
    For a = 1 To 12
      AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview")
    Next
    Repeat
      event = WaitWindowEvent()
      Select event
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              For i = 0 To CountGadgetItems(0)-1
                If GetGadgetItemState(0,i)
                  Debug "Item " + Str(i+1) + " selected."
                EndIf
              Next
          EndSelect
      EndSelect
    Until event = #PB_Event_CloseWindow
  EndIf
I may look like a mule, but I'm not a complete ass.
Post Reply