Reputation: 695
I created a checkbox using the method below:
for( i = 1; i<7; i++)
{
for (j = 1; j < 33; j++)
{
CheckBox a = new CheckBox();
a.Name = "SAT_ID_" + i.ToString() + "_" + j.ToString();
this.Sat_ID_Grid.Children.Add(a);
a.Style = (Style)Application.Current.FindResource("ReadOnlyCheckBox");
Grid.SetRow(a, i );
Grid.SetColumn(a, j );
}
}
Is it possible to reference the checkboxes later using "SAT_ID_X_Y"? I cant seem to find the solution. If not how can I reference them? I need to change the .ischecked state.
Thanks
Upvotes: 0
Views: 222
Reputation: 185553
Just store the references to the controls somewhere instead of their names, e.g. in a List<CheckBox>
, then you can access them by index.
Also you actually should not do any of that, use data-templating and data-binding to create controls for data. If done right you just need to change a boolean on your data and the check-box will be checked/unchecked.
Upvotes: 1