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
zacks@construction-imaging.com - 20 Aug 2007 20:03 GMT
> Hello All,
>
[quoted text clipped - 6 lines]
> Thanks
> Anand Ganesh
It's ListBox.Items.
Nicholas Paldino [.NET/C# MVP] - 20 Aug 2007 20:06 GMT
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.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Hello All,
>
[quoted text clipped - 7 lines]
> Thanks
> Anand Ganesh
SurferJoe - 20 Aug 2007 20:11 GMT
private void button1_Click(object sender, EventArgs e)
{
string s = "";
for (int i = 1; i <= lvwMyListView.Items.Count - 1; i++)
{
s = s + lvwMyListView.Items[i].Text + char.Parse("\n");
}
MessageBox.Show( s);
}
Anand Ganesh - 20 Aug 2007 21:59 GMT
Hello All,
Thank you very much for the quick reply and clarification.
Regards
Anand
> Hello All,
>
[quoted text clipped - 7 lines]
> Thanks
> Anand Ganesh