PureBasic Forum
http://forums.purebasic.com/english/

ListViewGadget() with Dynamic Horizontal ScrollBar [Windows]
http://forums.purebasic.com/english/viewtopic.php?f=12&t=72354
Page 1 of 1

Author:  RASHAD [ Mon Feb 25, 2019 3:18 pm ]
Post subject:  ListViewGadget() with Dynamic Horizontal ScrollBar [Windows]

Hi
The title say it all
Code:
   LoadFont(0,"Tahoma",12)
  If OpenWindow(0, 0, 0, 270, 200, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ListViewGadget(0, 10, 10, 250, 120,#WS_HSCROLL)
    For a = 1 To 12
      AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview")
    Next
   
    ButtonGadget(1,10,150,80,25,"Add item(s)")
    ButtonGadget(2,100,150,80,25,"Remove item")
   
    hdc = GetDC_(GadgetID(0))
    SetGadgetFont(0,FontID(0))
    fontid = GetGadgetFont(0)
    SelectObject_(hdc, fontid)
    size.SIZE
    sitem = -1
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          sitem = GetGadgetState(0)         
       
        Case 1         
          AddGadgetItem (0, -1, "Listview Listview  Listview  Listview  Listview Listview Listview")
          AddGadgetItem (0, -1, "Listview Listview  Listview  Listview  Listview Listview Listview Listview Listview")
          items = CountGadgetItems(0)
          SendMessage_(GadgetID(0),#LB_GETHORIZONTALEXTENT,0,0)
          For item = 0 To items
            text$ = GetGadgetItemText(0,item)           
            GetTextExtentPoint32_(hdc,@text$,Len(text$),size)
            If size\cx > oldcx
               oldcx = size\cx
            EndIf
          Next
          SendMessage_(GadgetID(0),#LB_SETHORIZONTALEXTENT,oldcx+10,0)
          oldcx = 0
         
        Case 2
          If sitem >= 0         
            RemoveGadgetItem (0,sitem)
            items = CountGadgetItems(0)
            SendMessage_(GadgetID(0),#LB_GETHORIZONTALEXTENT,0,0)
            For item = 0 To items
              text$ = GetGadgetItemText(0,item)           
              GetTextExtentPoint32_(hdc,@text$,Len(text$),size)
              If size\cx > oldcx
                 oldcx = size\cx
              EndIf
            Next
            SendMessage_(GadgetID(0),#LB_SETHORIZONTALEXTENT,oldcx+10,0)
            oldcx = 0 : sitem = -1
          Else
            MessageRequester("Info","No item selected ",#MB_OK|#MB_ICONINFORMATION)
          EndIf

      EndSelect             
  EndSelect
Until Quit = 1
EndIf


Edit : Update

Author:  Michael Vogel [ Tue Feb 26, 2019 8:24 am ]
Post subject:  Re: ListViewGadget() with Dynamic Horizontal ScrollBar [Wind

Well done :shock:

I was nervous for a second as the initial content does not get checked, but your code is great - I'd add a SetGadgetFont(0,FontID(0)) anyhow :wink:

Author:  RASHAD [ Wed Feb 27, 2019 1:41 pm ]
Post subject:  Re: ListViewGadget() with Dynamic Horizontal ScrollBar [Wind

Previous post updated

Author:  Kwai chang caine [ Thu Feb 28, 2019 1:00 pm ]
Post subject:  Re: ListViewGadget() with Dynamic Horizontal ScrollBar [Wind

Works great here
Thanks a lot for sharing 8)

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/