Results 1 to 4 of 4

Thread: Traverse Listbox Items

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    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.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: Traverse Listbox Items

    Code:
    foreach (string itm in lstbox.Items )
    			{
    				MessageBox.Show(itm);
    			}

  3. #3

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    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.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    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
  •  



Click Here to Expand Forum to Full Width