Check a checkbox if the row is selected.

Dec 1, 2008 at 8:19 PM
Edited Dec 1, 2008 at 8:21 PM

I want to create a DataGridTemplateColumn with a checkbox that is checked if the row is selected.  How I imagine this working is creating a DataGridTemplateColumn with checkbox which binds to an IsSelectedProperty on the cell?  Has anyone done this with data binding?


Dec 1, 2008 at 9:38 PM
   I was able to do this with the following DataTemplate:

 <DataTemplate x:Key="CheckSelect">
                        <CheckBox x:Name="cbxSelect_Row" Checked="cbxSelect_Row_Checked" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type toolkit:DataGridRow}}, Path=IsSelected, Mode=TwoWay}"
                          FontSize="14" Margin="0"></CheckBox>

However, the behavior is still not want I want.  Is there a way to have the DataGrid.SelectionMode = Multiple.  Where you do not have to hold down 'control' key to select multiple items?
Dec 2, 2008 at 7:55 AM

I have a post on my blog which describes using the Row header for displaying a checkbox which allows multiple selection:

This might be what you are looking for.

Colin E.
-- - my WPF blog - WPF DataGrid Practical Examples

Dec 2, 2008 at 2:23 PM

That is exactly what I am looking for. Thank you!
Dec 2, 2008 at 2:50 PM
Cool - glad to help.

Happy comments on my blog and positive ratings on my codeproject articles would be much appreciated ;-)

Have fun,

Colin E.
-- - my WPF blog - WPF DataGrid Practical Examples

Mar 30, 2009 at 8:17 AM
I want to achieve the same thing.
Colin, with your blogpost it does work, but I have a requirement, that there shall be a Checkbox in the columnheader too. So I put the Checkbox not in the rowheader, but into a column. This does not work like expected! Only the checkbox of the latest selected row remains checked! The Binding is:



TK:DataGridCheckBoxColumn Width="Auto" IsReadOnly="False" IsThreeState="False"



MinWidth="30" Binding="{Binding Path=IsSelected, Mode=TwoWay,



RelativeSource={RelativeSource FindAncestor,



AncestorType={x:Type TK:DataGridRow}}}">

The grid's selectionmode is extended...
Can somebody figure out what is going wrong?
Or can somebody give me a hint how to style the area above the rowheaders? This is the area where you can click and everything gets selected.
Thanks in advance!