jeudi 18 avril 2019

How do I sort a list of checkboxes by their name?

I have a foreach loop which fills a list with checkboxes from a groupbox. Problem is that they are added in a random order. Since I named them all in an ascending alphabetical order I want to sort them by their Name propery.

I've already tried using .Sort() but it doesn't do anything. Also I tried using a Linq expression DigBoxes = DigBoxes.OrderBy(x => x.Name).ToList();

But it also doesn't do anything...

Here's my code:

GroupBox box = (GroupBox)e.Argument;
            string DigInput = "";
            List<CheckBox> DigBoxes = new List<CheckBox>();

            foreach (Control c in box.Controls)
            {
                if(c is CheckBox)
                {
                    DigBoxes.Add(c as CheckBox);
                }
            }




Aucun commentaire:

Enregistrer un commentaire