Page 1 of 1

Possible to hide (not delete) ListIcon column?

Posted: Wed Oct 19, 2005 2:50 am
by kenmo
Hey, I'm back with another Windows gadget question... is there any way to hide a column of a ListIcon, without losing its data (aka deleting it)?? I have read the Win32 API help files I have, but they are outdated, and I can't find an answer.

Thanks in advance.

(edit)

OK, from googling the subject it seems it is impossible to actually hide the column, but settings its width to 0 does the same thing... except a user can then resize it visible again.

Posted: Wed Oct 19, 2005 8:25 am
by Hydrate
You could save all the items in a preference file, redraw the column empty(and set its width to 0 or something) and when you want it visible again add the items to it again(and extend its width once more), thats one way i could think of anyway.

Posted: Wed Oct 19, 2005 8:51 am
by DoubleDutch
You should be able to stop the user from changing the size with the window callback, something like (not tested):

Code: Select all

.
.
.

*nmhdr.NMHEADER = lparam
If *nmhdr\hdr\code=#HDN_ITEMCHANGING
  If *nmhdr\iItem=3 ; column 3?
    Result=#True ; stop column 3 from being resized!
  EndIf
EndIf
.
.
.
ProcedureReturn Result
Hope this helps...

-Anthony

Posted: Thu Oct 20, 2005 1:24 am
by kenmo
Hydrate wrote:You could save all the items in a preference file, redraw the column empty(and set its width to 0 or something) and when you want it visible again add the items to it again(and extend its width once more), thats one way i could think of anyway.
Yup. The problem though is that the user can drag columns with a width of 0 so they aren't really gone. I'm trying to have it so you can choose which columns to be included, which would kind of be pointless if they are all there and can be freely dragged.

DD - that looks good, I'll work on that.

Posted: Fri Oct 21, 2005 12:25 am
by kenmo
Allright, DoubleDutch, I'm dumb... firstly the message you told me will be sent to the listicon window, right? (aka the GadgetID()) and secondly, what would the wparam be?

Posted: Fri Oct 21, 2005 10:50 am
by DoubleDutch
It was slightly more complicated that I first thought - because replying with true when getting the #HDN_ITEMCHANGING message sometimes appears to lock the previous column (when the locked column size is zero).

So I had to try a slightly different method - here it is & it appears to work okay...

Code: Select all

Dim FixColumn(3)
#DefaultColumn1=200

Enumeration
	#MyWindow
	#MyGadget
	#HideButton
	#UnHideButton
EndEnumeration

Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
    Result = #PB_ProcessPureBasicEvents
    
    If Message=#WM_NOTIFY
			*nmhdr.NMHEADER = lParam 
			If *nmhdr\hdr\code=#HDN_ITEMCHANGING
  			If FixColumn(*nmhdr\iItem)
			  	*nmdata.HD_ITEM = *nmhdr\pitem
			  	*nmdata\cxy=0
  			EndIf 
			EndIf
		EndIf
		
    ProcedureReturn Result
    
  EndProcedure

If OpenWindow(#MyWindow,50,50,600,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"ListIcon Example")
  If CreateGadgetList(WindowID())
    ListIconGadget(#MyGadget,5,5,590,90,"Name",100,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(#MyGadget,1,"Address",#DefaultColumn1)
    AddGadgetColumn(#MyGadget,2,"Tel no",70)
    AddGadgetColumn(#MyGadget,3,"email",90)
    AddGadgetItem(#MyGadget,-1,"Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay"+Chr(10)+"01234 256252"+Chr(10)+"fred@blah.com")
    AddGadgetItem(#MyGadget,-1,"Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity"+Chr(10)+"01213 2562242"+Chr(10)+"george@bing.com")
    
    ButtonGadget(#HideButton,5,100,90,20,"Hide column")
    ButtonGadget(#UnHideButton,100,100,90,20,"UnHide column")
    
    SetWindowCallback(@MyWindowCallback())
    
    Repeat
      EventID = WaitWindowEvent()
      If EventID=#PB_EventGadget
        Select EventGadgetID()
      		Case	#HideButton
		      	SendMessage_(GadgetID(#MyGadget),#LVM_SETCOLUMNWIDTH,1,0)
		      	FixColumn(1)=#True
		      Case	#UnHideButton
      			FixColumn(1)=#False
			      SendMessage_(GadgetID(#MyGadget),#LVM_SETCOLUMNWIDTH,1,#DefaultColumn1)
	      EndSelect
      EndIf
    Until EventID = #PB_Event_CloseWindow And EventWindowID() = #MyWindow
  EndIf
EndIf

Posted: Fri Oct 21, 2005 7:52 pm
by kenmo
Gorgeous, and it even works with draggable headers. I appreciate it!

Posted: Fri Oct 21, 2005 9:39 pm
by DoubleDutch
np :)