views:

124

answers:

4

Hi !

I have a Form that has a panel with some textBoxes and checkBox that is outside the panel. Every time the Form is loaded the checkBox has focus.

I have put en event handler when form loads and tried to set focus on first textbox instead having it on the checkbox.

this.Activated += new EventHandler(form_Activated);

in the method i try to set the focus on the first textbox in the panel

        private void form_Activated(object sender, EventArgs e)
    {
        if (this.parametersPanel.Controls.Count > 0)
        {
            this.parametersPanel.Focus();
            (this.parametersPanel.Controls[0]).Focus();
        }
    } 

This does not work, can some1 help me pls?

+1  A: 

try setting the focus directly on the textbox instead of using panel's controls index.

VoodooChild
parametersPanel is loaded dynamicly. I dont have a property referencing the controls in the pannel ...
no9
it worked ! thanx
no9
A: 

Instead of Activated try Shown

tafa
What do you mean by that. Activated event works fine ... as will probably also Shown. The problem i have is setting the focus to the control inside panel.
no9
+1  A: 

In desing mode, select your control and set it's tabindex to 0

Ahmet Kakıcı
i did that. It does not help ! I tried setting parametersPanel tabIndex to 0 and i also tried setting tabIndex to the controls that get dynamically loaded to the panel. I think the problem is setting focus to a control that is within another control.
no9
A: 

Yoc can use the solution provided by Ahmet. Since you want the text box to have the focus...setting the tab index to zero will do that.

Also you can use the textbox'e focus method to set the focus, in the form's load event....

Pavan Navali