Hi,
If I have a listbox with rows, is it possible to convert it into text with specific format?
Let’s say the rows are like,
Column 0
1 apple
1 Orange
1 Pineapple
2 Banana
I am expecting the result to be in textfield like,
1 apple, 1 Orange, 1 Pineapple, 2 Banana
I want it to export to the text horizontally, Its really hard to do it with an array.
I have tried with this code, but only show the first row
dim g as integer
for g=Listbox1.Listcount -1 downto 0
TextField1.text=Listbox1.cell(g,0)+","
Listbox1.ListIndex=Listbox1.ListIndex+1
TextField1.text=Listbox1.cell(g,0)+","
next
any helps ?
thanks
regards,
arief
To get the result you are expecting you’d use
For g As Integer = 0 To Lisbox1.ListCount - 1
TextField1.SelText = Listbox1.Cell(g, 0) + " " + Listbox1.Cell(g, 1) + ", "
Next g
HTH
Dear Mr. Golding,
Thanks, the code is work perfectly.
Regards,
Arief
Only if you want only what is in Column(0) / your Row have only one column.
Dear mr. Schwarz,
Yes, actually I am bit confused with the code, but i dont know why its worked.
TextField1.SelText = Listbox1.Cell(g, 0) + " " + Listbox1.Cell(g, 1) + ", "
I have test it with one column, its worked, even its define array from column(0) and column(1), and test it with two columns also worked nicely.
but anyway, its help me a lot.
regards,
arief
Sorry that was a shortcut to getting your requirements. Seltext without a Selstart or sellength will append the string to the controls text element. It is the equivalent of
Dim s As String
For g As Integer = 0 To Lisbox1.ListCount - 1
s = s + Listbox1.Cell(g, 0) + " " + Listbox1.Cell(g, 1) + ", "
Next g
TextField1.Text = s