Hi Faith,
Thanks for your post. We can intercept TAB key in DataGrid control, and
then set the focus to corresponding Cell. Here is the detailed steps:
1. We must create a DataGrid-derived class in order to trap keytrokes in
the DataGrid. Please refer to the following code snippet:
//------------------code snippet------------------
public class MyDataGrid: DataGrid
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch(keyData)
{
case Keys.Tab:
this.CurrentCell = new
DataGridCell(this.CurrentCell.RowNumber+1,0);
return true;
}
}
return base.ProcessCmdKey(ref msg,keyData);
}
}
//------------------end of-------------------
2. In the Form class, declare and create the DataGrid as MyDataGrid.
CHANGE:
private System.Windows.Forms.DataGrid dataGrid1;
this.dataGrid1 = new System.Windows.Forms.DataGrid();
TO:
private MyDataGrid dataGrid1;
this.dataGrid1 = new MyDataGrid();
Please refer to the following KB article for detailed information:
HOW TO: Trap Keystrokes in .NET Controls by Using Visual C# .NET
http://support.microsoft.com/?id=320584
Hope this helps.
Regards,
HuangTM
Microsoft Online Partner Support
MCSE/MCSD
Get Secure! --
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.