Hi all,
I have a databound listbox and I want to traverse all the items in the listbox with a loop. For example, I want to print all the items of the listbox in Message Boxs one by one.
Thanks.
Printable View
Hi all,
I have a databound listbox and I want to traverse all the items in the listbox with a loop. For example, I want to print all the items of the listbox in Message Boxs one by one.
Thanks.
Code:foreach (string itm in lstbox.Items )
{
MessageBox.Show(itm);
}
Thanks Pirate, but this code doesn't work for me. It gives error messge "Specified cast is not valid.".
Actually, I have binded my listbox control with an ArrayList, DisplayMember property is String while the ValueMember is long.
yah , I thought that would error out (casting issue) . This should work :
Code:for (int i=0;i <lstbox.Items.Count ;i++)
{
MessageBox.Show(lstbox.Items[i].ToString());
}