C# 只能在datacontrolgrid的一个单元格/列中编辑一次

C# 只能在datacontrolgrid的一个单元格/列中编辑一次,c#,wpf,xceed,datagridcolumn,C#,Wpf,Xceed,Datagridcolumn,我有一个datacontrolgrid,它有三列,绑定到一个列表,还有一个clickevent(但我需要将它与键盘上的一个键结合起来,才能编辑所选的单元格/列)。我只想编辑这些列中的一列,因此在xaml文件中的特定列标记中有一个EditTemplate,其中的datatemplate包含一个文本框,其中包含一个keydown事件,在数据库中插入/更新该事件之前,我在实体上设置了值 在click方法中,我还检查是否按下了特定的键,如果是,我调用BeginEdit和Focus。但似乎从未调用EndE

我有一个datacontrolgrid,它有三列,绑定到一个列表,还有一个clickevent(但我需要将它与键盘上的一个键结合起来,才能编辑所选的单元格/列)。我只想编辑这些列中的一列,因此在xaml文件中的特定列标记中有一个EditTemplate,其中的datatemplate包含一个文本框,其中包含一个keydown事件,在数据库中插入/更新该事件之前,我在实体上设置了值

在click方法中,我还检查是否按下了特定的键,如果是,我调用BeginEdit和Focus。但似乎从未调用EndEdit,因为在第一个编辑的单元格之后,datagrid始终将标志IsBeingedit设置为true,并且不知何故它阻止我再次编辑。是否有一种方法可以在只监听回车键的keydown方法中提交编辑

XAML

        <xcdg:DataGridControl Grid.Row="1" 
                              VerticalAlignment="Top"
                              MouseRightButtonUp="MyMethod_RightClick"
                              ItemsSource="{Binding ListOfObjects}"
                              AutoCreateColumns="False"
                              Height="1000"
                              NavigationBehavior="RowOnly">

            <xcdg:DataGridControl.Columns>
                <xcdg:Column FieldName="Name" IsMainColumn="False" MinWidth="500">
                    <xcdg:Column.CellEditor>
                        <xcdg:CellEditor>
                            <xcdg:CellEditor.EditTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBox x:Name="txtbox" KeyDown="txtbox_KeyDown" Text="{xcdg:CellEditorBinding}" />
                                    </StackPanel>
                                </DataTemplate>
                            </xcdg:CellEditor.EditTemplate>
                        </xcdg:CellEditor>
                    </xcdg:Column.CellEditor>

你能添加一些代码吗?很难想象你正试图做什么/在哪里遇到什么issues@GordonAllocman我已经编辑了我的帖子。谢谢你的评论。你能添加一些代码吗?很难想象你正试图做什么/在哪里遇到什么issues@GordonAllocman我已经编辑了我的帖子。谢谢你的评论。
    private void MyMethod_RightClick(object sender, RoutedEventArgs e)
    {
        DataGridControl dataGrid = (DataGridControl)sender;
        MyObj myObj = (MyObj)dataGrid.CurrentItem;

        if (Keyboard.IsKeyDown(Key.E))
        {
            //i'm coming here all times i'm trying to edit records in one column but i'm only able to edit the first time i'm trying.
            dataGrid.BeginEdit();
            dataGrid.Focus();
            return;
        }
        //in case of no edit i do some other stuff...
    }


    private void txtbox_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key != Key.Enter) return;

        var txtboxvalue = ((TextBox)sender).DataContext.ToString();
        //do stuff and
        //set value on entity property and update record in db...
    }