listicongadget selected or not if pointing to the last

Just starting out? Need help? Post your questions and find answers here.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

listicongadget selected or not if pointing to the last

Post by MyTrial »

Hi

i have a silly question (i hope not) ;)

on a listicongadget i want to know if a line is selected or not. i need to show all of the list. so i define the last line to use. but when i get the state i get always the number of the last line - if selected or not. Do i something wrong? is there another way? or how can i see if nothing or the last is selected?

Code: Select all

If OpenWindow(0, 0, 0, 320, 200, "TEST", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  Flags = #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #LVS_NOCOLUMNHEADER
  ButtonGadget(1, 10, 5, 100, 30, "TEST")
  ListIconGadget(0,  10,  45, 300, 160, "Column 1", 100, Flags)
  For b = 2 To 4 
    AddGadgetColumn(0, b, "Column " + Str(b), 65)
  Next
  For b = 0 To 12
    AddGadgetItem(0, b, "Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
  SetGadgetState(0,CountGadgetItems(0) - 1)
  Repeat 
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget
      If EventGadget() = 0 Or EventGadget() = 1
        Debug GetGadgetState(0)
      EndIf
    EndIf
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
if you click the "test" button or select the last line, the same comes back.

thanks for your help.

Sigi
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: listicongadget selected or not if pointing to the last

Post by IdeasVacuum »

A few odd things in your code stopping it from working as intended, especially the loop. Anyway, use a callback, like this:

Code: Select all

#ListIcon = 1
#Btn = 2
Global igRow, igCol

Procedure.l WindowCallBack(WindowId.l, Message.l, wParam.l, lParam.l)
;-------------------------------------------------------------------

Shared igRow
Shared igCol

             iReturnValue.l = #PB_ProcessPureBasicEvents

   If Message = #WM_NOTIFY

          *msg.NMHDR = lParam
                                                                     ;Left Click
          If( (*msg\hwndFrom = GadgetID(#ListIcon)) And (*msg\code = #NM_CLICK) )

                                 *ListIcon.NMITEMACTIVATE = lParam
                         igRow = *ListIcon\iItem
                         igCol = *ListIcon\iSubItem
                  iReturnValue = #False
          EndIf
   EndIf

   ProcedureReturn iReturnValue

EndProcedure

Procedure OpenWin()
;------------------
If OpenWindow(0, 0, 0, 320, 300, "TEST", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

   SetWindowCallback(@WindowCallBack())
   Flags = #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #LVS_NOCOLUMNHEADER
   ButtonGadget(#Btn, 10, 5, 100, 30, "TEST")
   ListIconGadget(#ListIcon,  10,  45, 300, 160, "Column 1", 100, Flags)

   For b = 2 To 4
      AddGadgetColumn(#ListIcon, b, "Column " + Str(b), 65)
   Next

   For b = 0 To 12
     AddGadgetItem(#ListIcon, b, "Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4")
   Next
  ;SetGadgetState(0,CountGadgetItems(0) - 1)
EndIf

EndProcedure


OpenWin()

  Repeat

       iEvent = WaitWindowEvent(1)

    If iEvent = #PB_Event_Gadget
      Select EventGadget()
             Case #Btn
                  Debug "Row: " + Str(igRow)
                  Debug "Column: " + Str(igCol)
                  Debug GetGadgetItemText(#ListIcon,igRow,igCol)
                  Debug "---------------"  
      EndSelect 
    EndIf

  Until iEvent = #PB_Event_CloseWindow
Last edited by IdeasVacuum on Tue Dec 13, 2011 5:08 pm, edited 2 times in total.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Re: listicongadget selected or not if pointing to the last

Post by MyTrial »

Hi IdeasVacuum
thanks for your info. i think i did not explain very good what my wishes would be. maybe my bad english is the problem. sorry.
but your code does not what i want. i don't want a exit button, i want by using an other gadget (my test button) to see if something is selected in the listicon view. i do not really need the listicongadget select event to do something, i only want to see if something was selected or not. hope you understand me. sorry. ;)
Sigi
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: listicongadget selected or not if pointing to the last

Post by IdeasVacuum »

Hiya, edited code above :mrgreen:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Re: listicongadget selected or not if pointing to the last

Post by MyTrial »

Hi IdeasVacuum
Sorry, but your code helps no way, it complicates only anything. ;)
Your result is same as mine. You deleted my part to see the last item in the list - but I need that. So your result brings back the list item zero, which is the first item. That is same as selecting the first item in the list. I mean row, when I say "item". Non selecting gives "-1" back if nothing was selected - like my work to see the last list item. So my orginal code has the same result and is better readable with no complicated callback work.
Thank you, anyway for your help.
Sigi
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: listicongadget selected or not if pointing to the last

Post by RASHAD »

MyTrial Hi
I am not sure about your request but here is my turn

Code: Select all


If OpenWindow(0, 0, 0, 320, 200, "TEST", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  Flags = #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #LVS_NOCOLUMNHEADER 
  ButtonGadget(1, 10, 5, 100, 30, "TEST")
  ListIconGadget(0,  10,  45, 300, 160, "Column 1", 100, Flags)
  For b = 2 To 4 
    AddGadgetColumn(0, b, "Column " + Str(b), 65)
  Next
  For b = 0 To 12
    AddGadgetItem(0, b, "Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
  ;SetGadgetState(0,CountGadgetItems(0) - 1)
Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 0
              Result = 1
              
           Case 1
              If Result = 1
                Debug "Item Selected"
              Else
                Debug "No Item Selected"
              EndIf
              Result = 0            
          EndSelect
  EndSelect
Until Quit = 1
EndIf
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: listicongadget selected or not if pointing to the last

Post by IdeasVacuum »

I think it's Rashad to the rescue (once again!), but if you need the extra info my code reports, all you need to do is to have a non-existing row number as the default - for example, igRow = -1. Now in the loop test for the igRow number, if it is greater than -1, a row is selected, otherwise no row has been selected. Also note that the 1st column is column 0. Try it:

Code: Select all

#ListIcon = 1
#Btn = 2
Global igRow = -1, igCol = 0

Procedure.l WindowCallBack(WindowId.l, Message.l, wParam.l, lParam.l)
;-------------------------------------------------------------------

Shared igRow
Shared igCol

             iReturnValue.l = #PB_ProcessPureBasicEvents

   If Message = #WM_NOTIFY

               *msg.NMHDR = lParam
                                                                     ;Left Click
          If( (*msg\hwndFrom = GadgetID(#ListIcon)) And (*msg\code = #NM_CLICK) )

                                 *ListIcon.NMITEMACTIVATE = lParam
                         igRow = *ListIcon\iItem
                         igCol = *ListIcon\iSubItem
                  iReturnValue = #False

          EndIf
   EndIf

   ProcedureReturn iReturnValue

EndProcedure

Procedure OpenWin()
;------------------
If OpenWindow(0, 0, 0, 350, 400, "TEST", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

       SetWindowCallback(@WindowCallBack())

       Flags = #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines ;| #LVS_NOCOLUMNHEADER

         ButtonGadget(#Btn, 10, 5, 100, 30, "TEST")
       ListIconGadget(#ListIcon,  10,  45, 330, 200, "Column 0", 100, Flags)

       For b = 1 To 3
          AddGadgetColumn(#ListIcon, b, "Column " + Str(b), 65)
       Next

       For b = 0 To 12
            AddGadgetItem(#ListIcon, b, "Cell 0" + Chr(10) + "Cell 1" + Chr(10) + "Cell 2" + Chr(10) + "Cell 3")
       Next

       SetGadgetState(#ListIcon,CountGadgetItems(#ListIcon) - 1)

EndIf

EndProcedure


OpenWin()

  Repeat

       iEvent = WaitWindowEvent(1)
    If iEvent = #PB_Event_Gadget

      Select EventGadget()
             Case #Btn

                  If(igRow > -1)

                           Debug "Row: " + Str(igRow)
                           Debug "Column: " + Str(igCol)
                           Debug "Cell Contents: " + GetGadgetItemText(#ListIcon,igRow,igCol)
                           Debug "-----------------------"
                           igRow = -1;(reset row value ready for next test)
                  Else
                           Debug "No Row selected"
                           Debug "-----------------------"
                  EndIf
      EndSelect

    EndIf

  Until iEvent = #PB_Event_CloseWindow

End
Edit: I put your SetGadgetState() line back in, but this does not show all of the list, it just ensures that the last row can be seen.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Re: listicongadget selected or not if pointing to the last

Post by MyTrial »

Good Morning ;)

@IdeasVacuum
Thanks for your response. Now your's working. But you have a lot of overlay and complexity in your code for that simple part. Sorry.

@RASHAD
Thanks for your info. That is it. As simple as possible. I like that. Thank you very much.

Have nice christmas days.
Sigi
Post Reply