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.
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.
[/quote]
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.
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
else
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
next r
if colmax < colmin then colmax = colmin
end if
if colmax <> 0 then
cw = cw + str(colmax+15)
else
cw = cw + "0"
end if
next c
source.ColumnWidths = cw