1

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

Sheridan
  • 68,826
  • 24
  • 143
  • 183
user3428422
  • 4,300
  • 12
  • 55
  • 119

1 Answers1

3

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

Community
  • 1
  • 1
Damascus
  • 6,553
  • 5
  • 39
  • 53
  • For Info for others: I used the second link + When you declare isReadOnly on Xaml, to make it not readonly, use cell.IsEditing as cell.isReadOnly is a getter only! – user3428422 Jun 17 '14 at 13:41