How to disable the edit mode for certain rows based on specific condition?
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 }