'C# Get real tabindex order on winform

I'm trying to iterate through a list of controls by tabindex. But there are multiple controls within groupboxes, panels, etc that each start with 1, 2, etc. I set the order through the standard View-> TabOrder menu option.

IEnumerable<Control> cons = dxErrorHandler.GetControlsWithError();
foreach (Control ctl in cons.OrderBy(c => c.TabIndex))
    sb.AppendLine(dxErrorHandler.GetError(ctl));

This goes by e.g. Panel1.TabIndex 1, Panel2.TabIndex 1 instead of Panel1, TabIndex 1.1, Panel1, TabIndex 1.2, etc.

How can I iterate through controls in the same order set in View-> TabOrder

Thank you.



Solution 1:[1]

Jimi's answer worked. Didn't realize all controls belong to a "Parent". Nice to learns something new.

Thanks Jimi!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FirstByte