Listbox collection

A

Anand Ganesh

Hello All,

I want to go through each item in a Listbox collection. How will I do this?

I was looking for ListBoxItem but nothing is available?

Any suggestions please?

Thanks
Anand Ganesh
 
Z

zacks

Hello All,

I want to go through each item in a Listbox collection. How will I do this?

I was looking for ListBoxItem but nothing is available?

Any suggestions please?

Thanks
Anand Ganesh

It's ListBox.Items.
 
N

Nicholas Paldino [.NET/C# MVP]

Anand,

The listbox exposes the Items property, which returns a type of
ListBox.ObjectCollection. This type implements IEnumerable, which means you
can use in a for each statement.

The ListBox.ObjectCollection class holds instances of type object
though. The ListBox accesses the property indicated in the DisplayMember
property of the ListBox, or calls ToString on the object, if the
DisplayMember property does not have a value.

Also, if the list box is data-bound, then the Items property will have
no items in it, and you will have to access the listbox's data source
directly.
 
S

SurferJoe

private void button1_Click(object sender, EventArgs e)
{
string s = "";
for (int i = 1; i <= lvwMyListView.Items.Count - 1; i++)
{
s = s + lvwMyListView.Items.Text + char.Parse("\n");
}
MessageBox.Show( s);

}
 
A

Anand Ganesh

Hello All,

Thank you very much for the quick reply and clarification.

Regards
Anand
 

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