WPF中的DataGridCell编辑模式问题
问题是:WPF中的DataGridCell编辑模式问题,wpf,datagrid,mouseevent,wpf-4.0,datagridcell,Wpf,Datagrid,Mouseevent,Wpf 4.0,Datagridcell,问题是: 当我们想要编辑一个DataGridCell时,首先必须选择DataGridRow。我的意思是,要在DataGridRow.Current之外编辑DataGridCell,我们需要1单击单元格以选择第2行双击要进入编辑模式的单元格。我的问题是,我们如何只需单击一下就进入编辑模式?可能吗?首先,您可以将SelectionUnit=“Cell”设置为仅选择一个单元格 其次,可以使用键F2开始编辑 要在单击单元格时开始编辑,需要添加以下事件处理程序GotFocus: <DataGrid
当我们想要编辑一个
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);
}
}
}