这是问题所在:
当我们要编辑 aDataGridCell时,我们必须首先选择a DataGridRow。我的意思是在DataGridCell外部编辑DataGridRow.Current,我们需要 1.Click单元格选择行,2.DoubleClick单元格进入编辑模式。我的问题是我们如何只需单击一下就可以进入编辑模式?可能吗?
这是问题所在:
当我们要编辑 aDataGridCell时,我们必须首先选择a DataGridRow。我的意思是在DataGridCell外部编辑DataGridRow.Current,我们需要 1.Click单元格选择行,2.DoubleClick单元格进入编辑模式。我的问题是我们如何只需单击一下就可以进入编辑模式?可能吗?
First, you can set the SelectionUnit="Cell", was selected to only one Cell.
Second, you can start editing with key F2.
To start editing when you click on a Cell, you need to add the following event handler GotFocus:
<DataGrid Name="MyDataGrid" SelectionUnit="Cell" GotFocus="MyDataGrid_GotFocus" ...>
Code behind
private void MyDataGrid_GotFocus(object sender, RoutedEventArgs e)
{
if (e.OriginalSource.GetType() == typeof(DataGridCell))
{
DataGrid MyDataGrid = (DataGrid)sender;
if ((MyDataGrid != null) && (MyDataGrid.IsReadOnly == false))
{
MyDataGrid.BeginEdit(e);
}
}
}