Page 1 of 1

Automatically resize listicon columns?

Posted: Wed Aug 08, 2012 6:41 pm
by jassing
Is there a way (callback) to have the listicon automatically resize it's column based on recently added data?

Re: Automatically resize listicon columns?

Posted: Wed Aug 08, 2012 6:53 pm
by jesperbrannmark
Sure. Put this in the event of a if waitwindowevent()=#pb_event_sizewindow (or maximize)

Code: Select all

offset.f=GadgetWidth(0)/offset.f
SendMessage_(GadgetID(0),#WM_SETREDRAW,#False,0)
HideGadget(0,1)
SetGadgetItemAttribute(0, -1, #PB_ListIcon_ColumnWidth, 70*offset,0)  
SetGadgetItemAttribute(0, -1, #PB_ListIcon_ColumnWidth,120*offset,1)  
SetGadgetItemAttribute(0, -1, #PB_ListIcon_ColumnWidth,60*offset,2)  
SetGadgetItemAttribute(0, -1, #PB_ListIcon_ColumnWidth,150*offset,3)  
SetGadgetFont(0,FontID(0_font))  
HideGadget(0,0)  
SendMessage_(GadgetID(0),#WM_SETREDRAW,#True,0)
The value * offset is the original size, so you resize proportional.
the sendmessage stuff is to speed up.

Re: Automatically resize listicon columns?

Posted: Wed Aug 08, 2012 7:11 pm
by jassing
Don't need to resize the gadget, just a column, or did I misunderstand your code?

When I add a row, if the text is longer than the column, I want the column to resize to show all the text.

Re: Automatically resize listicon columns?

Posted: Wed Aug 08, 2012 7:41 pm
by RASHAD
Hi

Code: Select all

      OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
      ListIconGadget(0,  10,  10, 620, 280, "Column 0",80,#PB_ListIcon_GridLines)
      For x = 1 To 5
          AddGadgetColumn(0, x, "Column " + Str(x), 80)
      Next
      For x= 1 To 10
        AddGadgetItem(0, -1, "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 0                
                SetGadgetItemText(0, 2, "This is a Test For AutoSize",1)
                SendMessage_(GadgetID(0), #LVM_SETCOLUMNWIDTH,1,#LVSCW_AUTOSIZE)
                SetGadgetItemText(0, 4, "This is Test No two For AutoSize",3)
                SendMessage_(GadgetID(0), #LVM_SETCOLUMNWIDTH,3,#LVSCW_AUTOSIZE)
                
          EndSelect
  EndSelect
Until Quit = 1

Re: Automatically resize listicon columns?

Posted: Wed Aug 08, 2012 7:49 pm
by jassing
Than you Rasahd. I was failing because was thinking it had to be in a callback. that's much simplier that what I attempted. thank you.

Re: Automatically resize listicon columns?

Posted: Thu Aug 09, 2012 1:57 pm
by Zebuddi123
Easy procedure

Code: Select all

Procedure AutoResizeListGadgetColumn(gadget.l,position.l,text$,columwidth.l)
	SetGadgetItemText(gadget, position, text$,columwidth)
	SendMessage_(GadgetID(gadget), #LVM_SETCOLUMNWIDTH,columwidth,#LVSCW_AUTOSIZE)
EndProcedure



OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0,  10,  10, 620, 280, "Column 0",80,#PB_ListIcon_GridLines)
For x = 1 To 5
	AddGadgetColumn(0, x, "Column " + Str(x), 80)
Next
For x= 1 To 10
	AddGadgetItem(0, -1, "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 0               
					AutoResizeListGadgetColumn(0,2,"hello from Zebuddi make it bigggggggggggggggggggggg",1)
					AutoResizeListGadgetColumn(0,4,"And this is from Zebuddi even biggggggggggggggggggggggggggggggggggggggggger",3)
					
					;                 SetGadgetItemText(0, 2, "This is a Test For AutoSize",1)
					;                 SendMessage_(GadgetID(0), #LVM_SETCOLUMNWIDTH,1,#LVSCW_AUTOSIZE)
					;                 
					;                 SetGadgetItemText(0, 4, "This is Test No two For AutoSize",3)
					;                 SendMessage_(GadgetID(0), #LVM_SETCOLUMNWIDTH,3,#LVSCW_AUTOSIZE)
					
			EndSelect
	EndSelect
Until Quit = 1
zebuddi :)