Monday, March 15, 2010

How to select a row in the WPF DataGrid using a CheckBox

This is fairly simple to achieve in the WPF DataGrid, all you need to do is add a DataGridCheckBoxColumn to the Columns collection of the data grid, and then bind it to the IsSelected property of the DataGridRow that is hosting it.
    <local:PersonCollection x:Key="people">
        <local:Person ID="1" FirstName="Joe" LastName="Blow" />
        <local:Person ID="2" FirstName="Sam" LastName="Blam" />
        <local:Person ID="3" FirstName="Jack" LastName="Black" />
        <local:Person ID="4" FirstName="Hugo" LastName="Blue" />

    ItemsSource="{Binding Source={StaticResource people}}"
            Binding="{Binding IsSelected, 
                RelativeSource={RelativeSource AncestorType=DataGridRow}}" 

1 comment:

  1. This does work however it doesnt select multiple rows


Note: Only a member of this blog may post a comment.