mahesh waghela

mahesh waghela

  • NA
  • 93
  • 113.9k

Set Focus Problem With Usercontrol(DGV) And Other Controls(textBox)

May 6 2011 8:52 AM
I have a user control Datagridview which is derived from windows.forms.datagridview class and Textbox control in my forms and I have set the tabindex of control as below

Datagridview------ tabindex = 0

Textbox------------ tabindex =1

I have set mydatagridview as enter key like tab behavior and it's works fine but problem is that how to set focus on textbox control which is on main form by enterkey.

The code of Setting DGV by Enter keys as below:

public class mydatagridview : DataGridView 
        {
            protected override bool ProcessDataGridViewKey(KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter) 
                {
                    this.ProcessTabKey(e.KeyData);
                    return true;
                }
                return base.ProcessDataGridViewKey(e);
            }

            protected override bool ProcessDialogKey(Keys keyData)
            {
                if (keyData == Keys.Enter) 
                {
                    this.ProcessTabKey(keyData);
                    return true;
                    SendKeys.Send("{tab}");
                }
                return base.ProcessDialogKey(keyData);
            }
        }


How to Set Focus on Textbox by Enterkey on my main forms?.


Answers (19)