问题如下:
当我们想要编辑一个 DataGridCell
时,我们首先需要选择该行的 DataGridRow
。也就是说,如果要编辑 DataGridRow.Current
以外的 DataGridCell
,我们需要执行以下两个步骤: 1. 单击单元格以选择行,2. 双击单元格进入编辑模式。我的问题是:有没有可能只用一次单击就进入编辑模式?
问题如下:
当我们想要编辑一个 DataGridCell
时,我们首先需要选择该行的 DataGridRow
。也就是说,如果要编辑 DataGridRow.Current
以外的 DataGridCell
,我们需要执行以下两个步骤: 1. 单击单元格以选择行,2. 双击单元格进入编辑模式。我的问题是:有没有可能只用一次单击就进入编辑模式?
SelectionUnit="Cell"
,只选择一个单元格。F2
键开始编辑。GotFocus
:<DataGrid Name="MyDataGrid" SelectionUnit="Cell" GotFocus="MyDataGrid_GotFocus" ...>
代码后台
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);
}
}
}