Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Loop Through TabItem CheckBoxes

$
0
0

I have a group of 50 CheckBoxes that are placed inside a TabItem. On a button click, I need to loop through theCheckBoxes and based upon whether the CheckBox.Ischecked is true or false, it's relevant variable will be set to a 0 or a 1. 

Here is some code I've begun with to try and get a start;

    private void ApplyPrivilegeUpdateClick(object sender, RoutedEventArgs e)
    {
        var newPrivilegeModel = new EmployeePrivilegeModel();
        int i = 0;
        foreach (CheckBox c in companiesTabItem)
        {
            if (c.IsChecked == true)
            {
                newPrivilegeModel.Priv1 = 1;
            }
            i++;
        }
    }

newPrivlegeModel.Priv1 - This goes up to Priv50, so Priv1,Priv2, Priv3 etc etc. What I really don't want to have to do is do an `If` loop for all 50CheckBoxes and set their relevant Priv

I have two problems, how do I loop through all the 50 CheckBoxes in the TabItem? And how can I code the newPrivlegeModel.Priv1 so that they are all automatically updated? For example, newPrivlegeModel.Priv + idoes not work so how do I get round this?

I understand I could probably use collections and binding for this but I am a little unsure as I also have additionalTabItems with other CheckBoxes on them. I don't want to have to bind everyCheckBox to 250 different model properties.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>