Silverlight / WPF - Disable Row Selection Based on condition in datagrid in SL5

Asked By gopal krish on 23-May-12 08:24 AM
hi..

i want to Disable Row Selection Based on condition in datagrig in SL5?

how to achieve this..

need ur suggestions...
regards
gopal.s
[)ia6l0 iii replied to gopal krish on 29-May-12 10:33 PM
It should be a two stepped procedure -

a) Set the IsReadOnly property to true in the XAML
<ns:DataGrid x:Name="datagrid1"  ItemsSource="{Binding Data}" IsReadOnly="True">
</ns:DataGrid>


b) Add a "selectionchanged" event handler.
<ns:DataGrid x:Name="datagrid1"  ItemsSource="{Binding Data}" IsReadOnly="True" SelectionChanged="datagrid1_SelectionChanged">
</ns:DataGrid>
 

c) In the SelectionChanged event, choose to remove the selected item. Please see below.
private void datagrid1_SelectionChanged(object sender, SelectionChangedEventArgs e) 

    datagrid1.SelectedItem = null; 
}

Hope this helps.