I have a form that has many dynamically generated checkboxes. At runtime, how can I iterate through each of them so I can get their value and IDs?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Like this, maybe (if it's in Windows Forms):
When they are created, get a list of references to the values, and then you can iterate over the list.
If it is Windows Forms, you can try something like this:
Remember that container controls can contain children, so you might want to check those too.
I use a simple extension method that will work for any control type:
Then, you can use it like so:
Using IEnumerable lets you choose how to store the results, and also lets you use linq:
I know that this is old, but It was easy as I can imagine.
Just add all checkboxes into a
List<Checkbox>
, all checkboxes state are in the list and even if they change in the UI in the list changes too.Hope this helps :)