|
-
Dec 16th, 2004, 02:26 AM
#1
Thread Starter
Frenzied Member
Traverse Listbox Items
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.
-
Dec 16th, 2004, 05:25 AM
#2
Sleep mode
Re: Traverse Listbox Items
Code:
foreach (string itm in lstbox.Items )
{
MessageBox.Show(itm);
}
-
Dec 16th, 2004, 06:03 AM
#3
Thread Starter
Frenzied Member
Re: Traverse Listbox Items
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.
-
Dec 16th, 2004, 08:35 AM
#4
Sleep mode
Re: Traverse Listbox Items
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());
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|