by JBrooks
16. December 2011 09:54
I found this code on the internet to create a CheckBox in a DataGrid that wouldn’t require more than one click to change. But it didn’t work for me.
<sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<CheckBox IsThreeState="False" IsChecked="{Binding Path=IsActive, Mode=TwoWay}"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>
The reason it didn’t work is because I also had this as part of my DataGrid
<sdk:DataGrid CurrentCellChanged="dgTotals_CurrentCellChanged" …
That method had a dgTotals.BeginEdit(); in it to allow the user to begin editing the DataGrid cells without having to first click on them. The simple solution was to just skip that for my CheckBox column.
if(dgTotals.CurrentColumn != null && dgTotals.CurrentColumn.DisplayIndex != 1)
dgTotals.BeginEdit();
dde0bbc0-0616-4053-9f9f-44a44af79747|0|.0|27604f05-86ad-47ef-9e05-950bb762570c
Tags:
Development | Silverlight