0
votes

How does one get columns into a FireMonkey TListBox and then get the values out of the columns for the rows a TListBox. I am using this approach:

vListRow := 'Col1Stuff' + '^I' + 'Col2Stuff';

This is NOT giving me Col1Stuff in the 1st column and Col2Stuff in the 2nd Column.

I tried the TStringGrid Firemonkey control as an alternative, but the following approach is not working either:

vStringGrid.Cells[0,1] := 'Hi'; vStringGrid.Cells[0,2] := 'There';

This puts nothing in the TStringGrid.

Any tips?

1

1 Answers

4
votes

For the TListBox, use a tab character (#9):

ListBox1.Items.Add('Column A' + #9 + 'Column B');

To get the values out, you'd have to parse them back out, using the tab character as the delimiter (separator). It's usually more efficient and readable to use the ItemIndex instead, however.

Since you're doing direct concatenation, you can even omit the '+' (but you have to also remove the leading and trailing space:

ListBox1.Items.Add('Column A'#9'Column B');

For the TStringGrid, use the Items Editor to add two TStringColumns to the grid. You can then access the Cells property to read/write values - note that Cells are referenced by [column, row] values:

StringGrid1.Cells[0, 1] := 'Column A';   // Column 0, Row 1
StringGrid1.Cells[1, 1] := 'Column B';   // Column 1, Row 1