Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent DataGrid row from being deleted

I want to protect some rows of a DataGrid to be protected from deletion by the user, although the property CanUserDeleteRows is set to true.

Is there a possibility to protect some rows, hopefully through a databinding or a trigger? The ItemsSource is bound to an ObservableCollection of T.

like image 788
HCL Avatar asked Sep 12 '11 16:09

HCL


1 Answers

If you have a property on your bound objects that can be used to determine if the current row can be deleted , like 'IsDeleteEnabled', then you can bind the DataGrid's CanUserDeleteRows property to SelectedItem.IsDeleteEnabled.

For example,

<DataGrid Name="dataGrid1" 
        CanUserDeleteRows="{Binding ElementName=dataGrid1, Path=SelectedItem.IsDeleteEnabled}" 
like image 66
ChrisNel52 Avatar answered Oct 19 '22 09:10

ChrisNel52