We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to disable Edit mode for cells in SfDataGrid with different background for those disabled cells?

Platform: WPF |
Control: SfDataGrid |
.NET Framework: 4.5 |
Product Version:

In SfDataGrid, you can disable editing for particular columns by setting the AllowEditing property to False. Also you can disable editing for particular cells by handling the CurrentCellBeginEdit event.

In the CurrentCellBeginEdit event, you can cancel the Edit mode for certain cells by setting the Cancel property to True. In the following code, the Edit mode is disabled for the cells if the value is null.


            this.datagrid.CurrentCellBeginEdit += datagrid_CurrentCellBeginEdit;
private void datagrid_CurrentCellBeginEdit(object sender, CurrentCellBeginEditEventArgs args)
        var recordindex = this.datagrid.ResolveToRecordIndex
        if (recordindex >= 0)
            var reflector = this.datagrid.View.GetPropertyAccessProvider();
            var recorddata = this.datagrid.View.GroupDescriptions.Count > 0 ?         this.datagrid.View.Records[recordindex] :
          this.datagrid.View.TopLevelGroup.DisplayElements[recordindex] as RecordEntry;
            var value = reflector.GetValue(recorddata.Data, args.Column.MappingName);
            if (value == null)
                args.Cancel = true;

The following example has disabled Edit mode for cells using the CurrentCellBeginEdit event. For differentiating the Edit mode disabled cells, you can set separate background color for those cells by customizing styles for GridCell. Here, you can change the background property of the GridCell based on value, using CellBackgroundConverter

Refer the following code snippet to apply GridCell Style.


        <local:CellBackgroundConverter x:Key="cellbackgroundconverter"/>
<syncfusion:GridTextColumn MappingName="EmployeeDesignation" >
                    <Style TargetType="syncfusion:GridCell">
                        <Setter Property="Background" 
                                     Value="{Binding EmployeeDesignation, 
                              Converter = {StaticResource cellbackgroundconverter}}" />

Here, if the value of the cell is null, it means you have applied the background color Gray. The following code snippet for CellBackgroundConverter.


public  class CellBackgroundConverter : IValueConverter
        public object Convert(object value, Type targetType, 
        object parameter, System.Globalization.CultureInfo culture)
            if ( value==null)
                    return Brushes.Gray;
            return DependencyProperty.UnsetValue;
         public object ConvertBack(object value, Type targetType, 
         object parameter,    System.Globalization.CultureInfo culture)
  throw new NotImplementedException();

The following screenshot displays the difference between the Normal and Edit mode disabled cells.

Normal and Edit mode disabled cells


You can refer to the following samples to display the edit mode for cells in SfDataGrid with different background for the disabled cells.

WPF: DisableEditmode_WPF

WRT: DisableEditmode_Winrt

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile