I have a group of 50 CheckBoxes that are placed inside a TabItem. On a button click, I need to loop through the CheckBoxes 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 50 CheckBoxes 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 + i does not work so how do I get round this?
Aucun commentaire:
Enregistrer un commentaire