Disallowing Edit in a DataGridCell

Sep 8, 2008 at 10:12 PM
Is there a way I can disallow an edit of a particular cell of a data grid under specific circumstances?

For example, let's say I have the following:
                  
<tool:DataGridComboBoxColumn Header="Type" DataFieldBinding="{Binding XPath=@type}"
        ItemsSource="{Binding Source={StaticResource ProprtyTypes}}"/>
<tool:DataGridComboBoxColumn Header="Reference" DataFieldBinding="{Binding XPath=@ref}"
        DataFieldTarget="SelectedValue">
</tool:DataGridComboBoxColumn>

And I only want to allow you to edit the Reference field if the Type field is of a certain type, is there a way to do this?

In addition, is there a way to display an error tool tip (NOT a message box) if someone attempts to edit the field?

Coordinator
Sep 8, 2008 at 11:57 PM
In the final version you will have access to DataGridColumn.IsReadOnly which you can bind to and use a converter.  Another way to do this however is to listen to the DataGrid.BeginningEdit event and cancel the edit (e.Cancel = true;) there if your condition is true (in this case if Type is not the correct value for the Reference edit).  For the error tooltip you can do this in a couple of ways.  I am trying a couple of different approaches so I'll get back to you on it.
Sep 9, 2008 at 5:09 PM
Excellent.  Exaclty what I needed to know.  Thanks!