Hi,
I added an unbound column contains CheckBox. Xaml for this as below:
<ig:UnboundColumn Key="Select">
<ig:UnboundColumn.HeaderTemplate>
<DataTemplate>
<CheckBox x:Name="chkHeaer" Checked="chkHeaer_Checked" Unchecked="chkHeaer_Unchecked"/>
</DataTemplate>
</ig:UnboundColumn.HeaderTemplate>
<ig:UnboundColumn.ItemTemplate>
<CheckBox x:Name="chk" Checked="SelectRowCheckBox_Checked" Unchecked="SelectRowCheckBox_UnChecked"/>
</ig:UnboundColumn.ItemTemplate>
</ig:UnboundColumn>
Header checkbox checked/UnChecked event is
private void chkHeaer_Checked(object sender, RoutedEventArgs e) {
CheckBox chk = sender as CheckBox; foreach (Row row in grdBase.Rows) {
if (row.Cells[0].Control != null) { CheckBox chkBox = ((CellControlBase)(row.Cells[0].Control)).Content as CheckBox; chkBox.IsChecked = true; }
}
private void chkHeaer_Unchecked(object sender, RoutedEventArgs e) { CheckBox chk = sender as CheckBox; foreach (Row row in grdBase.Rows) { if (row.Cells[0].Control != null) { CheckBox chkBox = ((CellControlBase)(row.Cells[0].Control)).Content as CheckBox; chkBox.IsChecked = false; } } }
But on chkHeaderchekced/Unchecked event some of rows cell control have null references. i.e.
row.Cells[0].Control return null. so i am unable to get these rows checkbox references.
Can any one let me know why this happens or I am doing something wrong?
So, you shouldn't really be accessing your controls directly. The suggested way its to follow MVVM, where you don't access your controls directly, and you work through you data model instead, via a TwoWay binding.
However, if you don't have a bool property that you can bind to in your data, you can use the following sample i wrote, which uses a custom column and stores the value on a custom cell:
Hope this helps,
-SteveZ
I am facing problem to implement the Checkbox control on column header in caes of GroupBy. If grid is group by any column and user click on Header checkbox of any group, all other header row checkbox of other group is also checked/unchecked accordingly. I didn't find the reason why this happening like that.
Do you have a two way binding set up from your checkbox to a data item?
It sounds like you have a binding which when you update the first one toggling the value and all the other checkboxes which are bound to the same data item are seeing the change and responding.
In my scenario, I added a unbound column to xamGrid as follow:-
<ig:UnboundColumn Key="Select" IsGroupable="False" IsResizable="False" IsFilterable="False" EditorVerticalContentAlignment="Center" EditorHorizontalContentAlignment="Center" HorizontalContentAlignment="Center" HeaderTextHorizontalAlignment="{x:Null}" HeaderTextVerticalAlignment="{x:Null}">
<!-- Header template to add checkbox control in column header. -->
<CheckBox x:Name="HeaderCheckBox" Margin="2,2,0,0" Height="18" IsChecked="False" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center" Click="OnHeaderCheckBoxClick" Padding="0" />
<!-- Item template to diplay checkbox control instead of default cell control -->
<CheckBox x:Name="RowCheckBox" Height="18" IsChecked="False" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center" Click="OnRowCheckBoxClick" />
<!-- Filter item template to remove checkbox control from the fileter row -->
<ig:UnboundColumn.FilterItemTemplate>
<TextBlock/>
</ig:UnboundColumn.FilterItemTemplate>
<!-- Filter editor template to remove checkbox control from the fileter row -->
<ig:UnboundColumn.FilterEditorTemplate>
</ig:UnboundColumn.FilterEditorTemplate>
So when User enable the group by with any column, Groups are created based on the groupBy column value. Each group of rows have one header row and on each header row for on checkbox is visible for user. if user check/uncheck the header checkbox of any group's header row, other groups header row checkbox is also checked/unchecked accordingly.