Page 1 of 1

ListIcon Valid Column

Posted: Thu Sep 30, 2004 12:41 am
by Xombie
Code updated For 5.20+

I needed a way to loop through a listicon gadget's columns but couldn't find a way to determine the number of columns a listview has. So, I modified some code from the CodeArchiv and came up with ....

Code: Select all

Procedure.w liColumnIsValid(Gadget, index)
  ; Returns TRUE if a ListIcon Column (index) exists.
  lvc.LVCOLUMN
  lvc\Mask = #LVCF_TEXT
  txt.s = Space(255)
  lvc\pszText = @txt
  lvc\cchTextMax = 255
  SendMessage_(GadgetID(Gadget),#LVM_GETCOLUMN,index,@lvc)
  If Asc(Right(PeekS(lvc\pszText),1)) = 32 And Len(PeekS(lvc\pszText)) = 255 : ProcedureReturn #False : EndIf
  ProcedureReturn #True
EndProcedure
From the "Get&SetListIconColumnText.pb" file by Karbon, I believe.

Anyway, I needed it for this code:

Code: Select all

Procedure lvAutosizeControl(inGadget.l)
   ;Size Each column based On the maximum of EITHER the 
   ; columnheader Text Width, Or, if the items below it 
   ; are wider, the widest list Item in the column
   iLoop.l=0
   While liColumnIsValid(inGadget,iLoop) = #True
      SendMessage_(GadgetID(inGadget),#LVM_SETCOLUMNWIDTH,iLoop,#LVSCW_AUTOSIZE_USEHEADER)
      iLoop = iLoop + 1
   Wend 
EndProcedure
Which was in my VB project that I'm trying to convert and which I originally borrowed from http://vbnet.mvps.org/ quite a while back.

I'd love to see a proper way to do this. I just threw this together inbetween small breaks at work.

Posted: Thu Sep 30, 2004 1:04 am
by PolyVector
This should also work for counting columns....
I don't have time to test it though...

Code: Select all

#LVM_GETHEADER = (#LVM_FIRST + 31);/Shouldn't this be defined?

Procedure CountListIconColumns(ListIconGadgetNumber.l)
  Protected hListIcon.l,hHeader.l
  hListIcon=GadgetID(ListIconGadgetNumber);/A ListIconGadget's ID 
  hHeader=SendMessage_(hListIcon,#LVM_GETHEADER,0,0);/Get the Header's ID 
  ProcedureReturn SendMessage_(hHeader,#HDM_GETITEMCOUNT,#Null,#Null);/Get the number of columns
EndProcedure
Edit: I cleaned it up a bit for ya...