Skip to content

This demo shows how to avoid an InvalidOperationException when clicking AddNewRow while AllowEditing property is disabled for GridCheckBoxColumn in WPF DataGrid

Notifications You must be signed in to change notification settings

SyncfusionExamples/Avoid-InvalidOperationException-when-AddNewRow-is-clicked-if-AllowEditing-false-for-CheckBoxColumn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

How to avoid an InvalidOperationException when clicking AddNewRow while AllowEditing property is disabled for GridCheckBoxColumn in WPF DataGrid?

In WPF DataGrid (SfDataGrid), an InvalidOperationException will occur when attempting to add a new row for GridCheckBoxColumn while the AllowEditing property is false. This issue arises because the property bound to the GridCheckBoxColumn is read-only and provides only a getter.

The AddNewRow process is typically handled within the checkbox click event. This event depends on the IsHitTestVisible property. When IsHitTestVisible is set to false, the event is not triggered. This behavior is consistent with the framework's default handling of checkbox, which is influenced by the IsReadOnly property.

To prevent the exception, the IsReadOnly property should be set to true for the GridCheckBoxColumn. This configuration avoids triggering an InvalidOperationException during the process of inserting a new row with read only property.

<syncfusion:SfDataGrid x:Name="dataGrid"   
                       ItemsSource="{Binding Orders}" 
                       AutoGenerateColumns="False"
                       AddNewRowPosition="FixedTop"
                       AllowEditing="False">
    <syncfusion:SfDataGrid.Columns>
        <syncfusion:GridNumericColumn MappingName="OrderID" 
                                      HeaderText="Order ID"/>
        <syncfusion:GridTextColumn MappingName="CustomerName" 
                                   HeaderText="Customer Name"/>
        <syncfusion:GridTextColumn MappingName="Country" 
                                   HeaderText="Country"/>
        <syncfusion:GridCheckBoxColumn MappingName="Status"
                                       HeaderText="Status"
                                       IsReadOnly="True"/>
    </syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

AddNewRow for GridCheckBoxColumn

Take a moment to peruse the WPF DataGrid - Editing documentation, to learn more about editing with examples.

About

This demo shows how to avoid an InvalidOperationException when clicking AddNewRow while AllowEditing property is disabled for GridCheckBoxColumn in WPF DataGrid

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages