How to make rows readonly based on binding data

Dec 1, 2008 at 10:49 AM
Well the title says it all really - I have some data where some of the corresponding DataGrid rows need to be readonly whilst others should be editable based on a boolean field within the data..How do I achieve this?


Regards
Lee
Dec 1, 2008 at 10:59 AM
The BeginningEdit event is great for this.

        private void dataGrid_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
        {
            e.Cancel = ((e.Row.DataContext as MyDataType).IsReadOnly);
        }
Dec 1, 2008 at 11:03 AM
wow that was quick - thanks i'll give it a go!

Cheers
Lee
Dec 2, 2008 at 7:28 AM
Did it work for what you wanted to do?
Dec 2, 2008 at 10:34 AM
Well yes and no - it did what it said on the tin and stopped the editing but I also wanted the user to stop being able to delete the readonly row as well. In the end I derived from DataGrid and overrided OnCanExecuteDelete and OnBeginningEdit to achieve this.

Thanks for the help

Regards
Lee