Lock Column width in #ListIconGadget

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

PB wrote:That's the point: to stop the user changing the headers.
Nope, the point is size changes.
Rook Zimbabwe wrote:Is there any way to just LOCK the column widths?
Thus header dragging and sorting should still be supported. If dragging, sorting and sizing is disbaled the headercontrol is useless. Either use #LVS_NOCOLUMNHEADER or if you only need it for display purposes simply disable it or use #LVS_NOSORTHEADER.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

Not nearly so interesting, but you could simply do this:

Code: Select all

; Based on netmaestro's code
OpenWindow(0,0,0,320,240,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
CreateGadgetList(WindowID(0)) 
ListIconGadget(0,0,0,320,240,"Name",160) 
AddGadgetColumn(0,1,"Type",80) 
AddGadgetColumn(0,1,"Size",60) 
header = SendMessage_(GadgetID(0),#LVM_GETHEADER,0,0) 
EnableWindow_(header, #False) ; Disable the header
Repeat 
  ev = WaitWindowEvent(1) 
Until ev = #WM_CLOSE 
End
Anthony Jordan
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post by hallodri »

yes, remove all ui-functions from a header ... :?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

akj wrote:; Based on netmaestro's code
Sweet! Image

Hey, the first 5 lines are mine! Where the heck's my credit? Image
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
BarryG
Addict
Addict
Posts: 4131
Joined: Thu Apr 18, 2019 8:17 am

Re:

Post by BarryG »

Hi all, I'm using Fluid Byte's code to try to lock only column 3 from being shown (either by resizing or double-clicking it to show it). The following code fails, though. What am I missing? Thanks.

Code: Select all

Procedure WindowCallback(hWnd,uMsg,wParam,lParam)
  result=#PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *lpnm.NMHDR = lParam
      If *lpnm\hwndFrom = GetWindow_(GadgetID(0),#GW_CHILD) And *lpnm\code = #HDN_BEGINTRACK And *lpnm\idFrom = 3
        ProcedureReturn 1
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,320,240,"ListIcon",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ListIconGadget(0,0,0,320,240,"Name",80)
AddGadgetColumn(0,1,"Type",80)
AddGadgetColumn(0,2,"Size",80)
AddGadgetColumn(0,3,"Hidden",0) ; Never want this column to be seen.

SetWindowCallback(@WindowCallback())

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
User avatar
JHPJHP
Addict
Addict
Posts: 2252
Joined: Sat Oct 09, 2010 3:47 am

Re: Lock Column width in #ListIconGadget

Post by JHPJHP »

Hi BarryG,

See Windows Services & Other Stuff\Other_Stuff\GadgetStuff\ListIconGadget\HiddenColumn.pb
Last edited by JHPJHP on Sun Jan 01, 2023 7:09 pm, edited 1 time in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
BarryG
Addict
Addict
Posts: 4131
Joined: Thu Apr 18, 2019 8:17 am

Re: Lock Column width in #ListIconGadget

Post by BarryG »

Far out! That works great. Much appreciated. One tiny issue when #PB_ListIcon_GridLines are used, though: the gridlines are thicker than normal under the ListIcon header. (I forgot to mention I had gridlines). See code and image below. It seems a column of 0 width can't be fixed?

Maybe this code can do it? -> https://www.vbforums.com/showthread.php ... rom-sizing

Code: Select all

#LVCFMT_FIXED_WIDTH = $100

OpenWindow(0,0,0,320,240,"ListIcon",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ListIconGadget(0,0,0,320,240,"Name",80,#PB_ListIcon_GridLines)
AddGadgetColumn(0,1,"Type",80)
AddGadgetColumn(0,2,"Size",80)
AddGadgetColumn(0,3,"Hidden",1) ; Never want this column to be seen.

For i=1 To 5
  AddGadgetItem(0,-1,"Name"+#LF$+"Type"+#LF$+"Size"+#LF$+"Hidden")
Next

lv.LV_COLUMN : lv\mask = #LVCF_FMT : lv\fmt = #LVCFMT_FIXED_WIDTH
SendMessage_(GadgetID(0), #LVM_SETCOLUMN, 3, @lv)

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Image
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: Lock Column width in #ListIconGadget

Post by Lord »

Try

Code: Select all

AddGadgetColumn(0,3,"Hidden",-1) ; Never want this column to be seen.
This almost solved this.
Except for column header.
Image
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: Lock Column width in #ListIconGadget

Post by breeze4me »

Processing in #HDN_BEGINTRACK notification does not prevent a double click on a divider.
Double-click is possible by positioning the mouse cursor exactly on the 4th divider, and it expands the hidden column.
Therefore, it is better to process #HDN_ITEMCHANGING notification.

Image

Code: Select all

Procedure WindowCallback(hWnd,uMsg,wParam,lParam)
  result=#PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *lpnm.NMHEADER = lParam
      If *lpnm\hdr\hwndFrom = GetWindow_(GadgetID(0),#GW_CHILD) And *lpnm\hdr\code = #HDN_BEGINTRACK And *lpnm\iItem = 3
        Debug "Start the divider drag."
      EndIf
      
      If *lpnm\hdr\hwndFrom = GetWindow_(GadgetID(0),#GW_CHILD) And *lpnm\hdr\code = #HDN_DIVIDERDBLCLICK And *lpnm\iItem = 3
        Debug "The divider double-clicked."
      EndIf
      
      If *lpnm\hdr\hwndFrom = GetWindow_(GadgetID(0),#GW_CHILD) And *lpnm\hdr\code = #HDN_ITEMCHANGING And *lpnm\iItem = 3
        ProcedureReturn 1
      EndIf
      
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,320,240,"ListIcon",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ListIconGadget(0,0,0,320,240,"Name",80,#PB_ListIcon_GridLines)
AddGadgetColumn(0,1,"Type",80)
AddGadgetColumn(0,2,"Size",80)
AddGadgetColumn(0,3,"Hidden",0) ; Never want this column to be seen.
For i=1 To 5
  AddGadgetItem(0,-1,"Name"+#LF$+"Type"+#LF$+"Size"+#LF$+"Hidden")
Next

SetWindowCallback(@WindowCallback())

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
User avatar
JHPJHP
Addict
Addict
Posts: 2252
Joined: Sat Oct 09, 2010 3:47 am

Re: Lock Column width in #ListIconGadget

Post by JHPJHP »

Hi BarryG,

breeze4me might have a solution that fits your needs, but if not, and the hidden column is just to store information and the position of the column doesn't matter, make it the first column.

NOTE: On Windows 11 all the gridlines look the same, or I'm just old :)

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
BarryG
Addict
Addict
Posts: 4131
Joined: Thu Apr 18, 2019 8:17 am

Re: Lock Column width in #ListIconGadget

Post by BarryG »

Breeze4me's code works great for gridlines. Thanks to both of you!
Post Reply