C# .NET - Tab index : on nested user control on windows form

Asked By vivek P on 15-Dec-09 06:28 AM
    Hi all,
     I have complex windows form with nested user control. The tab index are not working properly even if set programatically while adding controls to form.
Can anybody suggest the what is wrong?

Thanks
Vivek

handle tabindex in user control controls properly

Santhosh N replied to vivek P on 15-Dec-09 06:34 AM
If you have child controls inside the user control, then the problem arises and for this you need to have tabindex for the user control handled and you can check http://www.codeproject.com/KB/user-controls/TabIndexUsercontrol.aspxon how to do that

Winform

vivek P replied to Santhosh N on 15-Dec-09 06:40 AM
I am dynamically creating the user controls and its contents form xml files.
e.g. one user control for one question and its options.


Set the property in a recursive function.

[)ia6l0 iii replied to vivek P on 15-Dec-09 07:23 AM
UserControl first - child controls immediately follow.

After you add all the controls to the form, loop thru the form instance in a recursive function which would look something similar to this:

Start the tabIndex with zero and increment it for each control of the form. If the control has children, fix them when you find them.

private  int tabIndex = 0;
private void FixControls(Control parentContainer)
{
            foreach (Control ctrl in parentContainer.Controls)
            {
                //set the tab order for  this control first. 
                if (ctrl.TabStop)
                {
                    ctrl.TabIndex = tabIndex++;
                }
                if (ctrl.HasChildren)
                    FixControls(ctrl);
            }
}

If this does not help, post your code. Let's have a brief look.

Hope this helps.