Исключение в редактировании ячеек WPF DataGrid - PullRequest
1 голос
/ 20 марта 2020

Я получаю приведенную ниже ошибку при редактировании события ячейки в WPF DataGrid.

enter image description here

Не могли бы вы помочь мне решить проблему?

Приведенный ниже код, который я использовал для редактирования значения ячейки

Код редактирования ячейки:

private void AutoBook_Datagrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
    {
        try
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {
                int primaryKey = 0;
                DataRowView editedRow = (DataRowView)mainWindow.autoBook_Datagrid.SelectedItems[0];
                if (editedRow != null && !string.IsNullOrEmpty(editedRow.Row["ID"].ToString()))
                {
                    primaryKey = Convert.ToInt32(editedRow.Row["ID"]);
                }
                if (e.EditingElement.ToString().Contains("TextBox"))
                {
                    if (e.EditingElement != null)
                    {
                        UpdateTextBoxValue(e.EditingElement as TextBox, e.Column.Header.ToString(), primaryKey);
                    }
                }
                else if (e.EditingElement.ToString().Contains("CheckBox"))
                {
                    if (e.EditingElement != null)
                    {
                        UpdateCheckBoxValue(e.EditingElement as CheckBox, e.Column.Header.ToString(), primaryKey);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

Связывание XAML:

<DataGrid
                    x:Name="autoBook_Datagrid"
                    HorizontalScrollBarVisibility="Auto"
                    VerticalScrollBarVisibility="Auto"
                    ScrollViewer.CanContentScroll="True"
                    BorderBrush="{StaticResource GreenBrush}"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top"
                    RowHeight="25"
                    GridLinesVisibility="All"
                    ClipboardCopyMode="IncludeHeader"
                    ItemsSource="{Binding DynamicBindingTable, UpdateSourceTrigger=PropertyChanged}"
                    CanUserAddRows="{Binding CanAddNewRows, UpdateSourceTrigger=PropertyChanged}"
                    VirtualizingPanel.VirtualizationMode="Recycling"
                    VirtualizingPanel.ScrollUnit="Pixel"
                    EnableColumnVirtualization="True"
                    EnableRowVirtualization="True"
                    FocusVisualStyle="{StaticResource ButtonFocusVisual}"
                        CanUserDeleteRows="False"
                    >

Сообщение об ошибке:

Unhandled Exception: System.ArgumentNullException: Value cannot be null.

Имя параметра: элемент в системе. Windows .Automation.Peers.UIElementAutomationPeer.FromElement (элемент UIElement) в системе . Windows .Controls.DataGrid.CellAutomationValueHolder.TrackValue () в Системе. Windows .Controls.DataGrid.ReleaseCellAutomationValueHolders () в Системе. Windows .Controls.DataGrid.OnExecuted .Controls.DataGrid.OnExecutedCommitEdit (Отправитель объекта, ExecutedRoutedEventArgs e)

С уважением, Арункумар Муругесан

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...