How can i make particular datagridcell writable,with the belonging column.Isreadonly=true

Apr 2, 2009 at 2:22 AM
Problem is that , i have a datagridcheckboxcolumn ,Header is "IsLockedOut".
Means that if the value in the column is true(The cell is in checked state),
the cell can be unchecked.But when the cell in the column is in unchecked state,
the cell can not be modified.

How can i do that?

Hope that  i have expained  clearly.

Any help would be appreciated,thanks~
Apr 3, 2009 at 9:52 PM
Edited Apr 3, 2009 at 9:56 PM
It cannot be done directly but you can achieve this using the logic below...

<dg:DataGrid ...>
                <CommandBinding Command="{x:Static dg:DataGrid.BeginEditCommand}" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed"/>


private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
DataGridCell cell = e.OriginalSource as DataGridCell;
if (cell != null)
        //what ever logic you need to cancel the edit
if (cell.Column == DataGrid_Standard.Columns[0] && ((Person)(cell.DataContext)).FirstName == "George")
            e.CanExecute =
            e.Handled =



private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)


Apr 3, 2009 at 10:16 PM
Edited Apr 4, 2009 at 4:08 PM
Can this be done without using Commands? Are there other events which can be tied to OR can the state of the cell be controlled through databinding alone?

For example, when the business object (row) is new and has never been committed to the database, the cell should be editable.  

When a business object is "old" or preexisting, the field to be readonly.

My business object has an attribute that I can bind to or evaluate that tells me if it is new or existing.

I'd like to do something like 

<DataGridTextBoxColumn.IsReadOnly = businessObject.IsNotNew>