You are here: Home

View Blog

Maintain Checkbox state in silverlight 4 datagrid paging

by Robin Gaschk on Thursday, 31 May 2012 11:39 PM
I came across the issue of where I was using a CheckBox within a DataGridTemplateColumn. I would click the checkbox of the first row and then page to the next page and the first row of the next page was also checked. The behaviour wasn't consistent.

Initially I had the column not bound to anything, then I included a IsChecked boolean to my collection type record and still got the same behaviour described when paging.

Then used the DataGridCheckBoxColumn and this gave the proper behaviour when paging, but the double click to select the checkbox was annoying. So I came across the following article which when I applied the binding syntax the checkbox selection and paging worked perfectly.

Just wanted to share for those that might get the same issue but not sure how to handle it. I have seen some convoluted approaches and this was easy.

<sdk:DataGridTemplateColumn Header="Processed">
     <sdk:DataGridTemplateColumn.CellTemplate>
           <DataTemplate>
                <CheckBox Content="{Binding Name}" IsChecked="{Binding Path=IsChecked,Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"></CheckBox>
           </DataTemplate>
     </sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>

Sourced from Guru's .Net Blog  here

Blogs Parent Separator Robin's Blog
Author
Robin Gaschk

The ramblings of a soapbox man