Search code examples
c#winformstabindex

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

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

    Thanks Jimi!