add listbox items

Posts 1–7 of 7 · Page 1 of 1
add listbox items
hi mpgh

how can i add for each line in a textbox a listboxitem with the text of the textbox

hope you can help me
[highlight="VB.Net"] Listbox1.Items.AddRange(Textbox1.Lines)[/highlight]
thank you blubb
is this also possible with a listview?
[highlight="VB.Net"] For i = 0 To Textbox1.Lines.Count - 1
Listview1.Items.Add(Textbox1.Lines(i))
Next[/highlight]

If that does not work...

[highlight="VB.Net"] For i = 0 To Textbox1.Lines.Count - 1
Dim LV as new listviewitem
LV.Text = Textbox1.lines(i)
Listview1.Items.Add(LV)
Next[/highlight]

Or do you want to have each further line in a subitem?

If so, you could do something like..

[highlight="VB.Net"] For i = 0 To Textbox1.Lines.Count - 1
Dim LV As New ListViewItem
LV.Text = Textbox1.Lines(0)
If i <> 0 Then LV.SubItems.Add(i)
Next

ListView1.Items.Add(LV)[/highlight]
Or just:

For new items per line:
[highlight=vb.net]
ListView1.Items.AddRange(TextBox1.Lines.Select(Fun ction(line As String) New ListViewItem(line)).ToArray())
[/highlight]

For subitems:
[highlight=vb.net]
Dim lvItem As New ListViewItem(TextBox1.Lines(0))
lvItem.Subitems.AddRange(TextBox1.Lines.Skip(1).Se lect(Function(line as string) new listviewitem.listviewsubitem(lvItem, line)).ToArray())
ListView1.Items.Add(lvItem)
[/highlight]
thanks you guys
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us