Articles in this section
Category / Section

How to disable the edit mode for certain rows based on specific condition in WPF GridDataControl?

1 min read

You can disable the edit mode in GridDataControl by using ConditonalFormats or by handling QueryCellInfo event.

Disable edit mode based on condition using ConditionalFormat:

Using ConditionalFormat you can define style for any Row(s)/Cell(s) by editing the Style property in the GridDataConditionalFormat class based on conditions. To disable the edit mode for a Cell/Row, you can set the ReadOnly property in the GridDataStyleInfo class as true.

Refer the following code example where edit mode is disabled for the entire row if the value in the “Companyname” column is “Syncfusion”. To apply the style for a particular column, you can use the ApplyStyleToColumn property in the GridDataConditionalFormat class.

XAML:

 

<syncfusion:GridDataControl.ConditionalFormats>
            <!--  to stop editing at some rows alone  -->
            <syncfusion:GridDataConditionalFormat Name="C1">
                <syncfusion:GridDataConditionalFormat.Style>
                    <syncfusion:GridDataStyleInfo ReadOnly="True" />
                </syncfusion:GridDataConditionalFormat.Style>
                <syncfusion:GridDataConditionalFormat.Conditions>
                    <syncfusion:GridDataCondition ColumnName="Companyname"
                                                      ConditionType="Equals"
                                                      Value="Syncfusion" />
                </syncfusion:GridDataConditionalFormat.Conditions>
            </syncfusion:GridDataConditionalFormat>
        </syncfusion:GridDataControl.ConditionalFormats>

 

Disable edit mode based on condition using QueryCellInfo event:

You can also define the style using the QueryCellInfo event for any row(s)/cell(s). To disable the edit mode for a Cell/Row, you can set e.Style.ReadOnly as true.

Refer the following code example where edit mode is disabled for the entire row if the value in the “Companyname” column is “Syncfusion”. To disable edit mode for a particular column/cell(s), the condition is modified using e.Style.CellValue.

C#:

griddata.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo); // to avoid edit mode using querycell info
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
        {
            var style = e.Style as GridDataStyleInfo; 
            var cellidentity = style.CellIdentity;
            var row = (cellidentity != null) ? cellidentity.Record as Employee : null;
            if (row != null && row.Companyname == "Syncfusion")
                e.Style.ReadOnly = true;            // to disable edit mode for entire row
        }



Conclusion

I hope you enjoyed learning about how to disable the edit mode for certain rows based on specific condition in WPF GridDataControl.

You can refer to our WPF GridData feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF GridData documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied