Page 1 of 1

List Icon Gadget: force number of columns

Posted: Mon Apr 23, 2012 6:44 pm
by IdeasVacuum
Scenario: You have a form with a ListIcon Gadget that has n Columns (say 0,1,2) and the Gadget is nailed to the form so that it will resize with it (I use gonzal's PureRESIZE lib).

The snag is that, when you drag the Window size out to the right, "column 3" is stretched to suit, rather than a column you are actually using. Is there a way around that conundrum?

Code: Select all

#Win = 0
#ListIcon = 1

Procedure OpenWin()
;------------------

          If OpenWindow(#Win, 100, 100, 400, 300,"4th Column",#PB_Window_SizeGadget|#PB_Window_SystemMenu|#PB_Window_TitleBar)

                          ListIconGadget(#ListIcon,10,25,380,250,"Col 0", 80,#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
                         AddGadgetColumn(#ListIcon, 1, "Col 1", 150)
                         AddGadgetColumn(#ListIcon, 2, "Col 2", 150)

                   ; Gadget Resizing
                     PureRESIZE_SetGadgetResize(#ListIcon, 1, 1, 1, 1)
                          SendMessage_(GadgetID(#ListIcon), #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_GRIDLINES, #LVS_EX_GRIDLINES)
          EndIf

EndProcedure


OpenWin()

          Repeat
                  iEvent = WaitWindowEvent(1)

           Until  iEvent = #PB_Event_CloseWindow

CloseWindow(#Win)
End

Re: List Icon Gadget: force number of columns

Posted: Mon Apr 23, 2012 8:08 pm
by RASHAD
Hi
I hope I understood you correctly.
Sorry I do not use any user lib.

Code: Select all

  Global Dim width(3)
  
  If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
    ListIconGadget(0,  10,  10, 620, 280, "Column 0", 200,#PB_ListIcon_GridLines)
      For x = 1 To 3 
        AddGadgetColumn(0, x, "Column " + Str(x), 300)
      Next
      For x = 0 To 8
        AddGadgetItem(0, x, "Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4")
      Next

Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
       
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1            
          EndSelect
          
      Case #WM_ENTERSIZEMOVE
          WWidth.d = WindowWidth(0)
          width(0) = GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,0)
          width(1) = GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,1)
          width(2) = GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,2)

          
      Case #WM_EXITSIZEMOVE
          ResizeGadget(0,10,10,WindowWidth(0)-20,WindowHeight(0)-20)
          Scale.d = WindowWidth(0)/WWidth
          SetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,Round(Scale*width(0),#PB_Round_Up),0)
          SetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,Round(Scale*width(1),#PB_Round_Up),1)
          SetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,Round(Scale*width(2),#PB_Round_Up),2)      
      
  EndSelect
Until Quit = 1
EndIf

Re: List Icon Gadget: force number of columns

Posted: Mon Apr 23, 2012 10:42 pm
by IdeasVacuum
Hi Rashad

That's exactly what I meant. 8)

I like the simplicity of your methods, I can apply those to other gadgets too. Thank you!

Re: List Icon Gadget: force number of columns

Posted: Tue Apr 24, 2012 3:46 am
by RASHAD
Hi IdeasVacuum
Enhanced Zoom Out - Zoom In ListIcon :)

Code: Select all

    
  If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
    ListIconGadget(0,  10,  10, 620, 280, "Column 0", 200,#PB_ListIcon_GridLines)
      For x = 1 To 9 
        AddGadgetColumn(0, x, "Column " + Str(x), 300)
      Next
      For x = 0 To 8
        AddGadgetItem(0, x, "Item 0"+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5"+Chr(10))
      Next
      
      Col_No = 9
      
      Global Dim width(Col_No)

Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
       
      
      Case #PB_Event_Gadget
            Select EventGadget()
             Case 1            
            EndSelect
            
            
      Case #WM_SIZE
            ResizeGadget(0,10,10,WindowWidth(0)-20,WindowHeight(0)-20)
            
          
      Case #WM_ENTERSIZEMOVE
            WWidth.d = WindowWidth(0)
            For i = 0 To Col_No
                width(i) = GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,i)
            Next
          
      Case #WM_EXITSIZEMOVE
            Scale.d = WindowWidth(0)/WWidth
            For i = 0 To Col_No
                SetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,Round(Scale*width(i),#PB_Round_Up),i)
            Next
      
  EndSelect
Until Quit = 1
EndIf


Re: List Icon Gadget: force number of columns

Posted: Tue Apr 24, 2012 3:23 pm
by IdeasVacuum
ah, not really sure what to expect with the second example - what ever it is, it does not seem to want to do it on my machine :) (WinXP 32bit, PB4.60). Not to worry, the first example does exactly what I need.

Re: List Icon Gadget: force number of columns

Posted: Wed Apr 25, 2012 12:31 am
by electrochrisso
ah, not really sure what to expect with the second example - what ever it is, it does not seem to want to do it on my machine :) (WinXP 32bit, PB4.60).
Resizes the ListIconGadget as the window size is being resized, you might have this feature switched off and only updating when the mouse is released. I am using Win7 Starter, PB4.60.