lundi 15 mars 2021

How do I get the checked status of a checkbox in c#? [closed]

I am a beginner at C#. I want to get the checked status of a checkbox. I have an array with the names of all of the checkboxes and I want to check them one by one to see if they are ticked or not. I think this has something to do with casting although I'm not really sure how to do that so please don't direct me to the documentation because I don't understand the mountain of technical references. I need a working example. Below is my erroneous attempt at trying to achieve this:

            for (int i = 0; i < getAllofTheActiveBays.Count; i++)
            {
                var checkbox = this.Controls.Find(getAllofTheActiveBays[i], true);
                var cb = checkbox as CheckBox;
                if (checkbox.Checked == true) //should this be .Equals("true")?
                {
                    //if a bay is ticked, add it to the activebays array
                    activeBays.Add(getAllofTheActiveBays[i].id);
                }
            }



Aucun commentaire:

Enregistrer un commentaire