0

I have a NumericUpDown control called "NumericIncrementPrecision" and when I change the value of this NumericUpDown it change for almost all NumericUpDown boxes the increment:

NumericTriggerLocationX.Increment = (decimal)NumericIncrementPrecision.Value;
NumericTriggerLocationY.Increment = (decimal)NumericIncrementPrecision.Value;
[...]
NumericObjectLocationYaw.Increment = (decimal)NumericIncrementPrecision.Value;

But I have 100+ NumericUpDown controls inside GroupBox inside TabPage inside Form, etc. I already tried this but nothing happening:

foreach (Control c in TabEditor.Controls)
{
    foreach (Control childc in c.Controls)
    {
        if (childc is NumericUpDown)
        {
            NumericUpDown test = (NumericUpDown)childc;
            test.Increment = (decimal)NumericIncrementPrecision.Value;
        }
    }
}

Any idea?

Thank you.

ASh
  • 34,632
  • 9
  • 60
  • 82
Nicko
  • 13
  • 2
  • 1
    Possible duplicate of [Loop through all controls on a form,even those in groupboxes](https://stackoverflow.com/questions/15186828/loop-through-all-controls-on-a-form-even-those-in-groupboxes) – ASh Apr 07 '18 at 18:15

1 Answers1

0

we need to go deeper:

foreach (Control c in TabEditor.Controls)
{
    // c will be a TabPage
    foreach (Control childc in c.Controls)
    {
        // childc is a control inside TabPage, e.g GroupBox
        foreach (NumericUpDown nud in childc.Controls.OfType<NumericUpDown>())
        {
            nud.Increment = (decimal)NumericIncrementPrecision.Value;
        }
    }
}

if all NumericUpDowns are in one GroupBox, then inspect only that GroupBox:

foreach (NumericUpDown nud in singleGroupBox.Controls.OfType<NumericUpDown>())
{
    nud.Increment = (decimal)NumericIncrementPrecision.Value;
}
ASh
  • 34,632
  • 9
  • 60
  • 82