DesktopListBox: Insert and populate a Row

Just to be sure I am walking in the good Alley:

a. Add a Row with .AddRowAt(RowIndex,"")
b. Fi-ll a Cell with .CellTextAt(RowIndex, "String")
c repeat b until all colum,ns are filled.

Is it correct ?

I use Add a Row with this syntax;
.AddRowAt(RowIndex,"col1 string","col2 string",...)

Alternatively if I want to add a row at the end of list just:
.AddRowAt("col1 string","col2 string",...)

If you are going to add a row to the end of the array, AddRow. If you want to add it at a specific location, use AddRowAt(RowIndex, Text)

https://documentation.xojo.com/api/user_interface/desktop/desktoplistbox.html

Another tip. If you type into the editor YourListBox.AddRow for example (your control + any method) you can hover over the method selected and you will see a description of the method right below, including the methods arguments.

If you right click the method name, you can also jump directly into the documentation for that method.

Thank You Sebastien,

I had near this syntax, .AddRowAt(RowIndex,aLine.Split(“,”) but was rejected at compile time.

Will look more closely after meal.

@Sveinn: Thank you. I already do what you suggest, but was insecure.

I have implemented Insert and Append. But this have to be translated to Xojo since Xojo does not knw about Insert and Append.

2 Likes

There is a problem with that syntax; I read the doc who tates:
image

My code:
LB_Pays.AddRowAt(InsertRow, aText.NthField(Chr(9),1), aText.NthField(Chr(9),2))

The error is: Missing Depth As Integer but found string.

You’re right @Emile_Schwarz correct syntax is:

.AddRow("col1 string","col2 string",...)

Insert:

LB_Pays.AddRowAt(InsertRow, "")
LB_Pays.CellTextAt(LB_Pays.LastAddedRowIndex, 0) = aText.NthField(Chr(9),1)
LB_Pays.CellTextAt(LB_Pays.LastAddedRowIndex, 1) = aText.NthField(Chr(9),2)

Append:

LB_Pays.AddRow("")
LB_Pays.CellTextAt(LB_Pays.LastAddedRowIndex, 0) = aText.NthField(Chr(9),1)
LB_Pays.CellTextAt(LB_Pays.LastAddedRowIndex, 1) = aText.NthField(Chr(9),2)

Insert: if a Row is selected, the new Row is inserted before that line.
If no Row is selected, the new Row is inserted at the beggining of the DesktopListBox.

1 Like

It is possible to write

Var tx As String 
ListBox1.ColumnCount = 3
tx = "France " + Chr(9) + "Belgique " + Chr(9) + "Suisse "  
ListBox1.AddRow (  tx.ToArray( Chr(9) )  )

That’s a bit messy…

A more clean approach :

ListBox1.AddRow(Array("France","Belgique","Suisse"))
1 Like

I want to Insert a Row.

The syntax is:

.AddRowAt(RowIndex, String)

I used the same code for Append, and there you are right.

Fortunately there are geniuses here !

2 Likes