Create a list of items that have been checked

246 views Asked by At

I have a tab page program, where I can select multiple check box items from each tab. I want to be able to create a list where it can show me the items i have selected. Below is my attempt at the beginning of a boo lean statement, however I'm stuck. Any suggestions on how to complete this would be amazing!

public bool itemchecked
{
    get 
    { 
        return checkBox.Checked; 
    }
}
1

There are 1 answers

0
nozzleman On BEST ANSWER

First: Add all you checkboxes to a List<CheckBox>.

Then your property could be sth. like

    public bool itemchecked
    {
        get
        { 
            var checkedBoxes = new List<CheckBox>();

            foreach(var item in AllCheckBoxes)
            {
                if(item.Checked)
                {
                   checkedBoxes.Add(item);
                }
            }

            return checkedBoxes;
        }
    }

You could also use a linQ-Expression to return the list.