Skip to content

How to conditionally enabled or disable CheckBox in WPF DataGrid (SfDataGrid) Column?

Notifications You must be signed in to change notification settings

SyncfusionExamples/how-to-conditionally-enabled-or-disable-check-box-in-wpf-data-grid-Column

Repository files navigation

How to conditionally Enabled or Disable CheckBox in WPF DataGrid Column?

This sample show cases how to conditionally enabled or disabled CheckBox in WPF DataGrid (SfDataGrid) Column.

The CheckBox check state will be updated based on the content for that specified cell in DataGrid. To update check state based on other column value in the same record, IValueConverter can be implemented and the Convert method can be implemented to have your own condition.

public class ChangeState : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var data = value as OrderInfo;
        if ((data.OrderID % 2) == 0) //To add your own condition
            return true;

        return false;
    }
}

To bind the converter for GridCells.

<Window.Resources>
    <local:ChangeState x:Key="converter" />
    <Style x:Key="cellStyle" TargetType="syncfusion:GridCell">
        <Setter Property="IsEnabled" Value="{Binding Converter={StaticResource converter}}" />
    </Style>
</Window.Resources>

<syncfusion:GridCheckBoxColumn CellStyle="{StaticResource cellStyle}" MappingName="Status" />

Enable or disable the check box by condition

About

How to conditionally enabled or disable CheckBox in WPF DataGrid (SfDataGrid) Column?

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7

Languages