We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

ListBox Checkbox

yanci1179
yanci1179 asked
on
Medium Priority
1,584 Views
Last Modified: 2008-02-26
In .Net 1.1 I used a listbox added checkboxes and use the following to check if something was checked:
 
if (LstFields.CheckedItems.Count > 0)

I tried using the same in  .Net 2.0 the .CheckedItems property does not exist.  Does anybody know the new syntax?

Thanks.

Comment
Watch Question

Carl TawnSenior Systems and Integration Developer
CERTIFIED EXPERT

Commented:
Are you using a standard ListBox or a CheckedListBox ?

Author

Commented:
in 1.1 I used a standart ListBox and then I just added the checkboxes.   There is a property called 'CheckBoxes' and I set it to true.  The property is not available in 2.0.  Was it removed?  I guess I can look at CheckedListBox
Carl TawnSenior Systems and Integration Developer
CERTIFIED EXPERT

Commented:
I assume that CheckedListbox is the replacement for a Listbox with the checkboxes option.

I tried a CheckedListBox in 2.0 and the CheckedItems member is there.

Author

Commented:
thanks, I am just going to go ahead and use the CheckedListBox (I don't really have a choice).

In 1.1. I used

foreach (ListViewItem li in LstFields.CheckedItems)

Do you know what the equivalent of ListViewItem is for the CheckedListBox

Carl TawnSenior Systems and Integration Developer
CERTIFIED EXPERT

Commented:
Well according to the documentation, CheckedListBox derives from ListBox so I would guess its the same as with the ListBox.

Author

Commented:
no, I'm getting an error when I use ListViewItem

Author

Commented:
In 1.1 I had a dynamic ListBox which would populate base on the users selection.  Then I used the text of the checkbox to create dynamic labels and textboxes:

I worked fine, but it does not work in 2.0


foreach (ListViewItem li in ChkLstFields.CheckedItems)
 {
       ct += 1;

       if (li.Text == "Method")
       {
          //create label based on the text
         //create combobox based on the text
        }
        else if (li.Text == "Neigh")
        {
            //create label based on the text
         //create combobox based on the text
         }
}
   
Senior Systems and Integration Developer
CERTIFIED EXPERT
Commented:
This seems to work, its a little odd that it appears to have gone from ListViewItem to string, but there we go:

            foreach (string c in checkedListBox1.CheckedItems)
            {
                MessageBox.Show(c);
            }

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
It Worked!!!!  Thanks so much!!!!!!!!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.