mardi 24 novembre 2015

Check a large group of checkboxes

I want to be able to say:

Get the first textblock, then the first checkbox, both with the number 1 in their name.

Then if the checkbox is checked, then the textblock can be populated.

See code:

     for (int i = 1; i < 10; i++)
        {

            TextBlock a = (this.FindName(string.Format("tb_{0}", i)) as TextBlock);
            CheckBox b = (this.FindName(string.Format("ck_{0}", i)) as CheckBox);
            if (b.IsChecked.HasValue)
            {
            if (a != null) a.Text = data.ArrayOfSensors[i].ToString();
            }
            else
            {
                if (a != null) a.Text = data.ArrayOfSensors[0].ToString();
            }

        }

So when the checkbox is enabled, the textblock will be populated with the index from the array.

Many thanks!




Aucun commentaire:

Enregistrer un commentaire