I’m writing a project that requires data to be displayed in a grid, and i’m trying the Listbox built into Xojo. Two questions:
How do I load an array variable into a cell? I try ‘ListBox1.Cell(ListBox1.LastIndex,1)=gage(1)’ and I get ‘Parameters are not compatible with this function’.
Is there a way to have the width of each area adjust to fit the contents? I have many 2 digit numbers, and don’t want to have a huge area just for a two-digit number.
Using Windows 8.1, latest version of Xojo.
Listboxes show & hold strings - only strings
So you’ll have to use functions like Format / Cdbl to put the data into the list & get it out
[quote=133723:@Derek DiBenedetto]- Is there a way to have the width of each area adjust to fit the contents? I have many 2 digit numbers, and don’t want to have a huge area just for a two-digit number.
Autoadjust ? No
The listbox would have to have ALL the data then figure out how wide the widest value in a column is and adjust itself to that width.
But you can specify the columns widths so you COULD do that yourself if its important.
You have to compute the width of each cell in the column(s) [in a loop], then set the largest value to the ColumnWidths Properties.
Many things have to be taking care of while doing that. Check ListBox, Max, For
Next, integer to string, string concatenation
automatic adjust the width of columns
dim source As Listbox = LB // your ListBox Name
dim r,c as Integer
dim pic as new Picture(1,1,32)
dim g as graphics = pic.Graphics
dim w as integer
dim colmax as integer
dim cw as string = ""
dim colmin as integer = 25
dim rows, cols as integer
dim cc as string
rows = source.ListCount-1
cols = source.ColumnCount-1
g.TextFont = source.TextFont
g.TextSize = source.TextSize
for c=0 to cols
if cw <> "" then cw = cw + ","
if source.Heading(c) = ":" then
colmax = 0
colmax = g.StringWidth(source.Heading(c))
for r=0 to rows
cc = source.Cell(r,c)
w = g.StringWidth(cc)
if w > colmax then colmax = w
if colmax < colmin then colmax = colmin
if colmax <> 0 then
cw = cw + str(colmax+15)
cw = cw + "0"
source.ColumnWidths = cw
Thanks Axel for sharing, this works pretty well!