Skip to main content Skip to footer

How to Set Individual Row IsReadOnly Property Based on Cell Value in C1DataGrid

To set the IsReadOnly property only for individual cells that contain a specific value in a specific column, you can specifically utilize the BeginningEdit event of the C1.WPF.Datagrid class. This is shown in the sample code below, where a grid contains a column where each cell either contains the values "Active" or "Inactive". If the cell value in the row is "Inactive", then the row should be editable: 

private void Grid_BeginningEdit(object sender, C1.WPF.DataGrid.DataGridBeginningEditEventArgs e)
{
    if (e.Column.Name == "IsReadOnly")
    {
        if ((e.Row.DataItem as Company).IsReadOnly == "Inactive")
        {
            e.Cancel = true;
        }
    }
}

Hunter Haaf