Bill Martin
Bill Martin

Reputation: 4943

How do I get the value (not check or unchecked) of a checkboxlist

I'm working on a winform app and am interating through a checkboxlist to see what's checked. If it's checked, i need to know what it's value member or value property is because I assigned it when I bound the checkbox list.

How can I get that?

Here's what I have now:

             for (int i = 0; i < clbIncludes.Items.Count; i++)

                if (clbIncludes.GetItemCheckState(i) == CheckState.Checked)
                {
                    //need the values of the checked checkbox here
                }");

Upvotes: 1

Views: 1625

Answers (1)

Mitch Wheat
Mitch Wheat

Reputation: 300559

foreach(object itemChecked in checkedListBox1.CheckedItems)
{
    MyItem item = itemChecked as MyItem;

    if (item != null)
    {
       // use item...
    } 
}

MSDN Ref.

Upvotes: 2

Related Questions