<local:ViewModel x:Key="viewmodel"/> <Style TargetType="Syncfusion:GridRowHeaderCell"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Syncfusion:GridRowHeaderCell"> <Border x:Name="PART_RowHeaderCellBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <Grid> <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Command="local:Commands.CheckAndUnCheck" CommandParameter="{Binding ElementName=datagrid}" /> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> |
public static class Commands { static Commands() { CommandManager.RegisterClassCommandBinding(typeof(CheckBox), new CommandBinding(CheckAndUnCheck, OnCheckUnCheckCommand, OnCanExecuteCheckAndUnCheck)); } public static RoutedCommand CheckAndUnCheck = new RoutedCommand("CheckAndUnCheck", typeof(CheckBox)); private static void OnCheckUnCheckCommand(object sender, ExecutedRoutedEventArgs args) { var orderinfo = (sender as CheckBox).DataContext as OrderInfo; var sfdatagrid = (args.Parameter as SfDataGrid); if (orderinfo.IsChecked) { orderinfo.IsChecked = true; sfdatagrid.SelectedItem = orderinfo; } else { orderinfo.IsChecked = false; } } private static void OnCanExecuteCheckAndUnCheck(object sender, CanExecuteRoutedEventArgs args) { args.CanExecute = true; } } |
CheckBox
in the expander cell of each node, which allows the user to check/uncheck the corresponding node. You can show the checkbox in expander cell by enabling ShowCheckBox property as “true”. For more details about NodeCheckBox and CheckBoxSelectionMode. <Style TargetType="syncfusion:TreeGridExpanderCell"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="syncfusion:TreeGridExpanderCell"> <Grid x:Name="Root"> <Border x:Name="PART_GridCellBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"> <Grid Margin="{TemplateBinding IndentMargin}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="0" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="0" /> </Grid.ColumnDefinitions> <syncfusion:TreeGridExpander x:Name="PART_ExpanderCell" Grid.Column="0" Width="12" Height="12" . . . . . . . . . . Converter={StaticResource boolToVisiblityConverter},Mode=TwoWay}" /> <CheckBox Name="PART_SelectCheckBox" Grid.Column="1" Width="16" . . . . . . . . . . Visibility="{Binding Path=ColumnBase.Renderer.TreeGrid.ShowCheckBox, RelativeSource={RelativeSource Mode=TemplatedParent},Converter={StaticResource boolToVisiblityConverter}, Mode=TwoWay}" /><Grid Grid.Column="2" Margin="3,0,0,0" Background="{TemplateBinding Background}"> . . . . . . . . . . </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <syncfusion:SfTreeGrid Name="treeGrid" AllowEditing="True" SelectionMode="Multiple" AutoGenerateColumns="False" AutoExpandMode="RootNodesExpanded" ChildPropertyName="Children" ShowCheckBox="True" CheckBoxSelectionMode="SelectOnCheck" ItemsSource="{Binding EmployeeDetails}"> <syncfusion:SfTreeGrid.Columns> <syncfusion:TreeGridTextColumn MappingName="TestCheck" AllowEditing="False" DisplayBinding="{Binding Converter={StaticResource checkBoxSelectionExt} }" HeaderText="" Width="0"/> <syncfusion:TreeGridNumericColumn MappingName="Id" /> <syncfusion:TreeGridTextColumn MappingName="FirstName" /> </syncfusion:SfTreeGrid.Columns> </syncfusion:SfTreeGrid> |
<syncfusion:SfDataGrid x:Name="dataGrid" AutoGenerateColumns="False"
ItemsSource="{Binding Orders}">
<syncfusion:SfDataGrid.Columns>
<syncfusion:GridCheckBoxSelectorColumn MappingName="SelectorColumn" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid> |
this.dataGrid.Columns.Add(new GridCheckBoxSelectorColumn()
{
MappingName = "SelectorColumn"
}); |