Listbox collection

  • Thread starter Thread starter Anand Ganesh
  • Start date Start date
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
 
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.
 
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.
 
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);

}
 
Hello All,

Thank you very much for the quick reply and clarification.

Regards
Anand
 
Back
Top