private void grd1_CurrentCellChanged(object sender, System.EventArgs e)
{
if (this.grd1.CurrentRowIndex < 0)
return;
System.Windows.Forms.DataGridCell cell = this.grd1.CurrentCell;
// Gets the DataGridTextBoxColumn from the DataGrid control.
DataGridTextBoxColumn oTextBoxColumn;
// Assumes the CompanyName column is a DataGridTextBoxColumn.
oTextBoxColumn = (DataGridTextBoxColumn)this.grd1.TableStyles[0].GridColumnStyles[cell.ColumnNumber];
// Gets the DataGridTextBox for the column.
DataGridTextBox oGridTextBox;
oGridTextBox = (DataGridTextBox) oTextBoxColumn.TextBox;
oGridTextBox.KeyDown+= new System.KeyEventHandler(this.YouTextKeyDownEvent);
}

解决方案 »

  1.   

    我也是这样实现的,但在DataGrid的
    oGridTextBox.KeyDown+= new System.KeyEventHandler(this.YouTextKeyDownEvent);
    中,回车键中不会触发该事件的!(其它键都会触发)
    Why!
      

  2.   

    那就没有招了,莫非是真的是DataGrid作了特殊处理。
    你可以尝试重新封装一次这个Grid,在外面接受事件,然后进行处理。看看行不行
      

  3.   

    写个NewDataGrid的类,(继承DataGrid),然后捆绑回车事件:oGridTextBox.KeyDown+= new System.KeyEventHandler(this.YouTextKeyDownEvent);
      

  4.   

    有錯誤﹕
     超出索引范圍﹕
    oTextBoxColumn = (DataGridTextBoxColumn)this.dataGrid1.TableStyles[0].GridColumnStyles[cell.ColumnNumber];