Hi All,
I am still getting used to the new objects.
Is there a way to force all the column headings in a listbox to be at least as wide as the heading text?
Thanks.
Hi All,
I am still getting used to the new objects.
Is there a way to force all the column headings in a listbox to be at least as wide as the heading text?
Thanks.
I suppose you could use g.textwidth to find out the width of the text and set the column widths accordingly, but what are you going to do about the Listbox width?
I would think that ListBox width would remain “X” and the user would use the horizontal scroll bar to see columns to the right.
Or am I mistaken about how the ListBox works?
I think you are.
Have-you read the dcumentation about the ListBox width ?
There are two different modes.
Is there a way to force all the column headings in a listbox to be at least as wide as the heading text?
As already stated, compute the width of your column heading text and set the column width for this column to that walue. Because there is only one width value for each Column, you will be OK.
Do that for all Columns if needed.
But remember to set the width value according to the “width mode”… (check the docs). (%, px, etc.)
Your assumption is correct.
Thanks @Emile_Schwarz and @Sascha_S
I was busy with a couple different things including some Argen stuff. I plan to revisit this later today.
This just needs the list to be passed to the method. It works well, but can be ‘fiddled’ with to fit your needs exactly. The listbox needs to have the horizontal scrollbar enabled,
Hope it helps, or at least gives you a starting point.
-Steve
Protected Sub ResizeListboxToFitColumns(pList as Listbox)
Var kColumnWidthMultiplier As Integer = 9
Var kColumnWidthAdditional As Integer = 10
Var iMaxWidth, iWidth, iHdrWidth As Integer = 0
Var sColWidths As String = ""
For i As Integer = 0 To pList.ColumnCount - 1
iMaxWidth = 0
iHdrWidth = pList.Heading(i).Len
For j As Integer = 0 To pList.ListCount - 1
iWidth = pList.Cell(j,i).Len
If iWidth > iMaxWidth Then iMaxWidth = iWidth
Next
If iHdrWidth > iMaxWidth Then iMaxWidth = iHdrWidth
sColWidths = sColWidths + Str((iMaxWidth * kColumnWidthMultiplier) + kColumnWidthAdditional) + ","
Next
sColWidths = Left(sColWidths,Len(sColWidths)-1)
pList.ColumnWidths = sColWidths
End Sub
Holy Cow @Steve_Cholerton1 !!!
I am definitely going to give this a try today.
Thanks!
Let me know how you get on. It should just work, I think the code is 10 or 15 years old, just updated a few years back to use Var Instead of Dim. Cheers - Steve