ListBox.AddRow Method have three syntax as far as the docs tell us.
ListBox.AddRow ( ParamArray Item as String )
Appends Item in a new row to the end of the list. Because it is called ParamArray, you can pass several items for a multicolumn ListBox. The items are separated by commas and will be the values for the various columns.
I never understand what code I have to write to make that working
For testings, I wrote:
[code] Dim Foo(2) As String
Me.AddRow Foo() // Row added, no String
Me.AddRow Foo(0),Foo(1),Foo(2) // Row added, no String
Me.AddRow “One”,“Two”,“Three” // Strings added
Me.AddRow “Single” // Row Added, string in Column(0)
How can I add a new row with a string variable and fill all Columns ?
[quote]ListBox.AddRow ( ParamArray Item as String )
Appends Item in a new row to the end of the list. Because it is called ParamArray, you can pass several items for a multicolumn ListBox. The items are separated by commas and will be the values for the various columns.[/quote]
lbx.AddRow("text0", "text1", "text2")
[quote]ListBox.AddRow ( Item() as String )
Appends a new row to the end of the list with each element of Item as a separate column.[/quote]
lbx.AddRow(Array("text0", "text1", "text2"))
Actually the docs are misleading. It has only two implementations. But if you pass no string, you pass an empty array for paramarray.
[quote=78720:@Emile Schwarz]Me.AddRow Foo() // Row added, no String
Me.AddRow Foo(0),Foo(1),Foo(2) // Row added, no String[/quote]
These work like you’re thinking, it’s the Foo array that’s wrong.
When you “Dim Foo(2) As String” it starts with indices 0, 1, 2. Then you Append the strings at indices 3, 4, 5.
Make the column count 6 and you’ll see “Me.AddRow Foo()” working.
Or better, start off with “Dim Foo() As String” for an empty array.
Actually, I added a small ListBox (150 x 200) at a window border and so I could not see my error !
Also, I was not clear enough: the real question was "how when I load text from a textfile (using TextInputStream), I can use .AddRow and fill the whole columns in on line of code).
Oh, I understand now why I do not understand previously
Thank for your replies.
Read a line, split it into an array and pass that into AddRow()
[code] lb.ColumnCount = 4
dim f As FolderItem = SpecialFolder.Desktop.Child(“test.txt”)
dim tis As TextInputStream = TextInputStream.Open(f)
while not tis.EOF
better define a text encoding for the TextInputStream…
Why ? I use UTF-8 by default !
What if I import text file(s) from unknown origin ? So, yes Christian, you are right: I have to define a Text Encoding.
Well, if you don’t define text encoding, the texts have no encoding and strange things can happen.
Yes, but the default encoding in Xojo is UTF-8.
My rule is:
For every string which comes from an external source I use DefineEncoding.
For every string which goes to an external target I use ConvertEncoding.
Unless you are absolutely sure that the source or target uses utf8 - but even then I do it.
(external source/target means databases, files, tcpsockets, …)
For TextInputstream you can simply set the encoding property if you know what encoding it has.
When converting from a memoryblock to a string, it has no encoding. It is necessary to DefineEncoding to UTF-8.
So the assumption that all chains are necessary UTF-8 because they are used in Xojo is not always true.
[quote=79015:@Emile Schwarz]Yes, but the default encoding in Xojo is UTF-8.
Not for text read from the outside. Xojo may have known it was UTF-8 when you wrote it, but when you read it back in, it has no idea. You have to define it explicitly when you read it in.