How to display "all" the items of listbox?

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!
 
T

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?

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
 
A

Armin Zingler

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
 
T

Teemu

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top