Listbox ... third column?

http://documentation.xojo.com/index.php/Listbox

[code]Dim i as Integer

For i = 0 to Self.ControlCount-1 //number of controls in window
ListBox1.AddRow Str(i) //first column
ListBox1.Cell(Listbox1.LastIndex,1)=Control(i).Name //second column
Next[/code]

About 40 cm down this page, the code can be found. I’m dealing with this and I don’t know it my code is wrong or where the issue is.
I want to add another column.
Is this the way to do it??
(I have tried various alternatives and so far, none has worked, that’s why the question.)

[code]Dim i as Integer

For i = 0 to Self.ControlCount-1 //number of controls in window
ListBox1.AddRow Str(i) //first column
ListBox1.Cell(Listbox1.LastIndex,1)=Control(i).Name //second column
ListBox1.Cell(Listbox1.LastIndex,2)=Control(i).Name //3:rd column
ListBox1.Cell(Listbox1.LastIndex,3)=Control(i).Name //4:th column
ListBox1.Cell(Listbox1.LastIndex,4)=Control(i).Name //5:th column
ListBox1.Cell(Listbox1.LastIndex,5)=Control(i).Name //6:thcolumn
Next[/code]

You just want to add a column? As this example fills the listbox with the names of the controls on the current window and is a bit confusing. You can add columns in the inspector pane or in code:

Listbox1.Columncount = 6

or

Listbox1.Columncount = Listbox1.Columncount + 1

Create a new project. Put a Listbox on the window and a button.
Switch ‘Has heading’ on in the Inspector pane of the listbox, otherwise you don’t see any new columns in a blank listbox.
Double click on the button and add an ‘action’ event.

In the code of the Action put :

Listbox1.Columncount = Listbox1.Columncount + 1

Save and run. Click on the button and you will see a new fresh column with every click… :wink:

Thank you very much for the very well-done example!!

However, it is not my question and it’s all my fault, I write so bad questions…
Let me try again:
I have today, a working code with TWO columns. I’m now expanding this code to three columns and it is failing and now I ask, what is the problem??
Do I write the line “Listbox1.LastIndex,2” for the third column?

yes, exactly.

First, set the nmer of columns correctly (1-based)
listbox1.colimnCount = 3

Then adress your cloumn #3 (zero-based!) via listbox1.cell(listbox1.listindex, 2) = …

sorry for writing errors - a little early in Germany…

listbox1.columnCount = 3

Then adress your column #3 (zero-based!) via listbox1.cell(listbox1.listindex, 2) = …

ListBox are 0-based, so:

listbox1.columnCount = 3

Set the ListBox to 4 columns.

Warning:

ListBox.ListIndex:
The selected item number.

So, if no selected items, the returned value will be -1.

For an “everywhere” use syntax I will wrote:

ListBox1.Cell(Row,Column)
Row: the Row number (0-based)
Column: the Column number (0-based)

So, if you want to read Row 1, Cell 3 ( the 4th Column of the 2nd line), use:

ListBox1.Cell(1,3)

I hope this is now crystal clear.

[quote=58606:@Emile Schwarz]ListBox are 0-based, so:

listbox1.columnCount = 3
Set the ListBox to 4 columns.

[/quote]

ListIndex is 0 Based… ListCOUNT is 1 based as it is a COUNT of columns

Thank you for taking the time to write these answers. There are many things to take care of. It’s still not working, but I think the issue in this moment is the lack of data in the database…

Thank you for the valuable and appreciated input!

lack of data in the database

Yes, you have to have a text file with the data you want to put in the database FIRST !

Then, add the code to import these data (from the text file),

If you have to modify the order of the data (read from the text file) at import time, you may want to export them in the correct order: write that code,

at last, if you export the data in a correct order (in a text file), add a variant to the import process to choose the kind of data you import (correct order or original order).

Then, add code to modify record(s) contents.

Once you will be there, you will be happy to be done that because if an error arise in the process right now, you do not are and trash the data base file [you do not loose data].

HTH,

Emile