views:

157

answers:

3

Hi All,
I have a situation that needs to conditionally make readonly to wpf datagrid cell. There is IsReadOnly property in DataGridCell. But unfortunately, that property is readonly! Is there any way to do it?
ant.

+1  A: 

You should be able to use the DataGrid.BeginningEdit event to conditionally check if the cell is editable and then set the Cancel property on the event args if not.

Josh Einstein
A: 

The exact solution for your requirements is found here :)

http://blog.spencen.com/2009/04/25/readonly-rows-and-cells-in-a-datagrid.aspx?results=1

hope it helps

VoodooChild
This one shows how to change the background color of a cell based on IsReadOnly flag. What I want to do is to set IsReadOnly flag of a cell based on runtime condition.
Ant
A: 

You could also use the TemplateSelector property to set two different DataTemplates (one writable and one readonly) based on your logic? Just create a class that inherits from DataTemplateSelector and override the SelectTemplate() method (here you have access to the datacontext).

Goblin