How to display "all" the items of listbox?

  • Thread starter Thread starter kimiraikkonen
  • Start date Start date
K

kimiraikkonen

Hi,
I want to display ALL the items (includes unselected items) of listbox
control. How can i code this? Should i use "for each" or other?

For example:
Assume you have a listbox with 3 items sth like:

Hello
There
Guys

And i want to display them in the same format within a messagebox with
seperated each line(maybe i have to use " + vbnewline"?).

How to do this?

Thanks!
 
kimiraikkonen said:
Hi,
I want to display ALL the items (includes unselected items) of listbox
control. How can i code this? Should i use "for each" or other?

For example:
Assume you have a listbox with 3 items sth like:

Hello
There
Guys

And i want to display them in the same format within a messagebox with
seperated each line(maybe i have to use " + vbnewline"?).

How to do this?

Thanks!

ListBox1.Items.Add("1")
ListBox1.Items.Add("2")
ListBox1.Items.Add("3")

Dim buffer As New System.Text.StringBuilder
For i As Integer = 0 To ListBox1.Items.Count - 1
buffer.AppendLine(ListBox1.Items(i).ToString)
Next
MsgBox(buffer.ToString)

-Teemu
 
kimiraikkonen said:
Hi,
I want to display ALL the items (includes unselected items) of
listbox control. How can i code this? Should i use "for each" or
other?

For example:
Assume you have a listbox with 3 items sth like:

Hello
There
Guys

And i want to display them in the same format within a messagebox
with seperated each line(maybe i have to use " + vbnewline"?).

How to do this?

If language = VB 2008 AndAlso all items in the list are Strings:

MsgBox(String.Join(vbCrLf, Me.ListBox1.Items.Cast(Of String).ToArray))


Armin
 
If language = VB 2008 AndAlso all items in the list are Strings:

MsgBox(String.Join(vbCrLf, Me.ListBox1.Items.Cast(Of String).ToArray))

Quite handy. LINQ makes everything too easy. :-)

-Teemu
 
Back
Top