Possible to hide (not delete) ListIcon column?

Just starting out? Need help? Post your questions and find answers here.
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Possible to hide (not delete) ListIcon column?

Post 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.
Hydrate
Enthusiast
Enthusiast
Posts: 436
Joined: Mon May 16, 2005 9:37 pm
Contact:

Post 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.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Post 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.
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Post 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?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Post by kenmo »

Gorgeous, and it even works with draggable headers. I appreciate it!
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

np :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply