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?.
Sam HobbsPosted May 9, 2011, 2:24 AM
Don't ask me why there is both a ProcessDialogKey method and a ProcessDataGridViewKey method; I don't know why but it seems to be necessary.
mahesh waghelaPosted May 10, 2011, 1:32 PM
Sam HobbsPosted May 10, 2011, 1:24 PM
VulpesPosted May 10, 2011, 1:03 PM
mahesh waghelaPosted May 10, 2011, 11:59 AM
It's a good solution which is attached here. I am appreciate your efforts and thanks for the same.And by the way there is no need of third control to add. It will run by add it directly to the main controls/parent control and it will executed.
Now I want to discuss about your line of second post on 09 may 2011 " in the IDE the template for creating an Inherited User Controls is for creating a control that inherits from another control.".
Generally Controls are inherited from common base class or Microsoft Control.And User Controls are always derived from the Common base Class Or Microsoft Windows Controls and hence User Controls cannot inherited like Microsoft controls as it's derived from the Microsoft Controls.
Sam HobbsPosted May 10, 2011, 12:51 AM
Sam HobbsPosted May 9, 2011, 2:44 AM
So I certainly misunderstood the original question because it says "user control Datagridview". I don't know for sure but that might be what some people in Microsoft call a control that is inherited from a DataGridView, but that sure confused me.
Yes, Windows programmers used the terms subclass and window class before C++ classes were designed; many years before .Net existed.
VulpesPosted May 8, 2011, 6:16 AM
mahesh waghelaPosted May 8, 2011, 5:39 AM
Sam HobbsPosted May 8, 2011, 12:22 AM
As for the original question, today was a busy day for me. I spent more time on the application idle question than I have on any question lately. I will look at this some more when I can.
VulpesPosted May 7, 2011, 6:15 PM
Sam HobbsPosted May 7, 2011, 5:29 PM
MFC for example did subclass controls to allow derived classes to be used and then there was a problem that the derived classes would not process Windows messages sent prior to the subclassing. The .Net classes don't have that problem.
VulpesPosted May 7, 2011, 3:22 PM
mahesh waghelaPosted May 7, 2011, 12:03 PM
Sam HobbsPosted May 7, 2011, 11:35 AM
mahesh waghelaPosted May 7, 2011, 10:58 AM
Sam HobbsPosted May 6, 2011, 7:37 PM
mahesh waghelaPosted May 6, 2011, 12:28 PM
VulpesPosted May 6, 2011, 11:24 AM
You'll need to set the Form's KeyPreview property to true and then handle the Form's KeyDown event as follows:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && ActiveControl == mydatagridview1)
{
Point p = mydatagridview1.CurrentCellAddress;
if (p.Y == mydatagridview1.Rows.Count - 1 && p.X == mydatagridview1.Columns.Count - 1)
{
this.SelectNextControl(ActiveControl, true, true, true, true);
e.Handled = true;
}
}
}