Automatically resize listicon columns?

Windows specific forum
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Automatically resize listicon columns?

Post by jassing »

Is there a way (callback) to have the listicon automatically resize it's column based on recently added data?
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Automatically resize listicon columns?

Post 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.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Automatically resize listicon columns?

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: Automatically resize listicon columns?

Post 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
Egypt my love
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Automatically resize listicon columns?

Post 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.
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Automatically resize listicon columns?

Post 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 :)
malleo, caput, bang. Ego, comprehendunt in tempore
Post Reply