Select an item in the table

Just starting out? Need help? Post your questions and find answers here.
zxretrosoft
Posts: 20
Joined: Sun Jan 25, 2015 10:37 am
Location: Prague, Czech Republic
Contact:

Select an item in the table

Post by zxretrosoft »

One more question.
If user selects a city no. 1 than Debug output must be City 1. If user selects a city no. 2 than output must be City 2 etc.
I can not figure it out ... Thanks a lot! ;)

Code: Select all

Declare database()
Declare detection()
Declare CloseWindowevent()

database()

Procedure database()  
  OpenWindow(1,0,0,410,200,"Example...")
  
  ListIconGadget(1,5,5,400,180,"Name",60,#PB_ListIcon_FullRowSelect|
                                         #PB_ListIcon_GridLines|                                  
                                         #PB_ListIcon_CheckBoxes)
  AddGadgetColumn(1,2,"Number 1",100)
  AddGadgetColumn(1,3,"Number 2",55)
  
  AddGadgetItem(1,-1,"City 1"+Chr(10)+"1243"+Chr(10)+"324891")
  AddGadgetItem(1,-1,"City 2"+Chr(10)+"23544"+Chr(10)+"91211")
  AddGadgetItem(1,-1,"City 3"+Chr(10)+"415"+Chr(10)+"1242")
  
  BindEvent(#PB_Event_Gadget,@detection())
  BindEvent(#PB_Event_CloseWindow,@CloseWindowEvent())
EndProcedure


;output - I need to detect the selection of cities (1,2,3...)
Procedure detection()
  ev.i=EventGadget()
  Debug(ev)
EndProcedure


;close window
Procedure CloseWindowEvent()
  CloseWindow(EventWindow())
EndProcedure
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Select an item in the table

Post by Peter »

take a look at GetGadgetState() and GetGadgetItemText():

Code: Select all

EnableExplicit

Declare database()
Declare CloseWindowEvent()
Declare ListIconGadget_Cities_Event()

database()

Enumeration ; Windows
  #Window
EndEnumeration

Enumeration ; Gadgets
  #ListIconGadget_Cities
EndEnumeration

Procedure database()  
  
  OpenWindow(#Window, 0, 0, 410, 200, "Example...")
  
  ListIconGadget(#ListIconGadget_Cities, 5, 5, 400, 180, "Name", 60, #PB_ListIcon_FullRowSelect|
                                                                     #PB_ListIcon_GridLines|                                  
                                                                     #PB_ListIcon_CheckBoxes)
  
  AddGadgetColumn(#ListIconGadget_Cities, 2, "Number 1", 100)
  AddGadgetColumn(#ListIconGadget_Cities, 3, "Number 2", 55)
  
  AddGadgetItem(#ListIconGadget_Cities, -1, "City 1" + #LF$ + "1243" + #LF$ + "324891")
  AddGadgetItem(#ListIconGadget_Cities, -1, "City 2" + #LF$ + "23544" + #LF$ + "91211")
  AddGadgetItem(#ListIconGadget_Cities, -1, "City 3" + #LF$ + "415" + #LF$ + "1242")
  
  BindEvent(#PB_Event_CloseWindow, @CloseWindowEvent())
  BindGadgetEvent(#ListIconGadget_Cities, @ListIconGadget_Cities_Event())
  
EndProcedure


Procedure ListIconGadget_Cities_Event()
  
  ; output - I need to detect the selection of cities (1,2,3...)
  
  Protected EventGadget
  Protected SelectedRow
  Protected SelectedCity.s
  
  EventGadget  = EventGadget()
  SelectedRow  = GetGadgetState(EventGadget)
  SelectedCity = GetGadgetItemText(EventGadget, SelectedRow, 0) ; Column 0 is our City
  
  Debug "SelectedRow: " + Str(SelectedRow)
  Debug "SelectedCity: " + SelectedCity
  Debug "-----"
  
EndProcedure

;close window
Procedure CloseWindowEvent()
  CloseWindow(EventWindow())
EndProcedure
Greetings ... Peter
zxretrosoft
Posts: 20
Joined: Sun Jan 25, 2015 10:37 am
Location: Prague, Czech Republic
Contact:

Re: Select an item in the table

Post by zxretrosoft »

Peter, thank you very much! It's exactly what I need! :) Thanks!! ;)
User avatar
SparrowhawkMMU
Posts: 291
Joined: Wed Aug 19, 2015 3:02 pm
Location: United Kingdom

Re: Select an item in the table

Post by SparrowhawkMMU »

Apologies for jumping in on your thread, but I wondered whether you could explain one more thing: In the above example, how would I tell whether a checkbox had been selected on the selected row? I have tried various approaches including the following change to the ListIconGadget_Cities_Event() procedure:

Code: Select all

Procedure ListIconGadget_Cities_Event()
 
  ; output - I need to detect the selection of cities (1,2,3...)
 
  Protected EventGadget
  Protected SelectedRow
  Protected SelectedCity.s
  Protected CityIsChecked
 
  EventGadget   = EventGadget()
  SelectedRow   = GetGadgetState(EventGadget)
  SelectedCity  = GetGadgetItemText(EventGadget, SelectedRow, 0) ; Column 0 is our City
  CityIsChecked = GetGadgetItemState(EventGadget, 0)
 
  Debug "SelectedRow: " + Str(SelectedRow)
  Debug "SelectedCity: " + SelectedCity
  
  If CityIsChecked = #PB_ListIcon_Checked
  	Debug "City is Ticked: Yes" 
  Else
  	Debug "City is Ticked: No" 
  EndIf
  
  Debug "-----"
 
EndProcedure
But the "City is Ticked:" string always displays "No" in the debug window

I could not tell how to do this from the SB Help files but I may have missed something obvious?

Thanks in advance.
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Select an item in the table

Post by Peter »

Code: Select all

  If GetGadgetItemState(EventGadget, SelectedRow) & #PB_ListIcon_Checked
    Debug "City is checked"
  Else
    Debug "City is not checked"
  EndIf
Greetings ... Peter
zxretrosoft
Posts: 20
Joined: Sun Jan 25, 2015 10:37 am
Location: Prague, Czech Republic
Contact:

Re: Select an item in the table

Post by zxretrosoft »

Perfect Peter, thanks a lot! ;)
User avatar
SparrowhawkMMU
Posts: 291
Joined: Wed Aug 19, 2015 3:02 pm
Location: United Kingdom

Re: Select an item in the table

Post by SparrowhawkMMU »

Yes thank you Peter: Works great. :)
Post Reply