ListView gadget with MultiColumn (Windows)

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4635
Joined: Sun Apr 12, 2009 6:27 am

ListView gadget with MultiColumn (Windows)

Post by RASHAD »

Just for fun

Code: Select all

LoadFont(0,"Tahoma",14)

OpenWindow(0, 0, 0, 480, 400, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListViewGadget(0, 10, 10, 450, 380 ,#LBS_MULTICOLUMN)
SetGadgetFont(0,FontID(0))
For a = 0 To 30
  AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview") ; define listview content
  text$ = GetGadgetItemText(0,a)
  If Len(text$) > maxwidth
    maxwidth = Len(text$)
    text2$ = text$
  EndIf
Next
ClearGadgetItems(0)
StartDrawing(WindowOutput(0))
DrawingFont(FontID(0))
w = TextWidth(text2$)+20  
StopDrawing()
SendMessage_(GadgetID(0),#LB_SETCOLUMNWIDTH,w,0)
ResizeGadget(0,#PB_Ignore,#PB_Ignore,2*w+30,#PB_Ignore)
SendMessage_(GadgetID(0),#LB_GETITEMRECT,0,r.RECT)
columnwidth = r\right+10
columnheight = r\bottom
nitem = GadgetHeight(0)/columnheight - 1
SendMessage_(GadgetID(0),#LB_SETCOLUMNWIDTH,columnwidth,0)

For a = 1 To nitem
  AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview") ; define listview content
Next
For a = nitem+1 To 30
  AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview") ; define listview content
Next

SetGadgetState(0, 9)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Egypt my love