1
votes

I am trying to turn off the isReadOnly property of a WPF Datagrid cell via c#. I need to do this once a user clicks on a row.

I have this so far

 private void dgProductItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
 {
     DataGrid dg = sender as DataGrid;

     if (dg != null)
     {
        DataGridRow dgr = (DataGridRow)(dg.ItemContainerGenerator.ContainerFromIndex(dg.SelectedIndex));
     }
  }

But how do I get down to the cell level via the

DataGridRow

So finally I am looking for cell.ISReadOnly = false/true;

Cheers

1
you want to make column read only? - Sajeetharan
I have the column set is read only = true in the XAML, however, on particular rows I want to change this to false - user3428422

1 Answers

3
votes

If you want to work on the DataGridCell object, you are going to need a little bit more code than expected

Check the answer here and use the TryTofindGridCell method to retrieve the DataGridCell object and then set its IsreadOnly property

Alternatively you can also check the solution described here to retrieve DataGridRows / DataGridCell