I have a datagrid and my purpose is to select multiple rows when the checbox cell of the row is checked. Problem is that one row is selected always. IsSelected property of the previous checked rows return false if i select one row. Please check the code behind. When checkbox of any row is checked, i set the IsSelected property to true. Next check of other rows remove the previous selections. I don't know the reason.
Xaml
<DataGrid VirtualizingStackPanel.VirtualizationMode="Standard" EnableColumnVirtualization = "True" EnableRowVirtualization ="True" x:Name="deckGrid" Grid.Row="3" ItemsSource="{Binding DeckList}" AutoGenerateColumns="False"
SelectionMode="Extended" Margin="10,10,0,0" SelectionUnit="FullRow" SelectionChanged="deckGrid_SelectionChanged">
<DataGrid.Columns >
<DataGridTemplateColumn Width="70" >
<DataGridTemplateColumn.HeaderTemplate >
<DataTemplate>
<CheckBox Name="ckbSelectedAll" IsThreeState="True" Margin="10,0,0,0" IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:DeckDefinition}, Path=AllSelected}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{x:Static local:DeckDefinition.UnCheckedCommand}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{x:Static local:DeckDefinition.CheckedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<CheckBox IsChecked="{Binding IsChecked, UpdateSourceTrigger=PropertyChanged}" Name="cbkSelect" Margin="10,0,0,0" Checked="CheckedTest"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="{lex:LocText Key=name, Dict=general, Assembly=KillCardMain}" Binding="{Binding Path=Name}" ></DataGridTextColumn>
<DataGridTemplateColumn HeaderStyle="{StaticResource CollapsedHeaderStyle}" CellStyle="{StaticResource NoBackgroundCellStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Width="32" Style="{DynamicResource NoBackgroundButtonStyle}" Click="DeleteRowBtnClicked">
<Image Source="/KillCardMain;component/Resources/Images/delete.png" Width="16"></Image>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn HeaderStyle="{StaticResource CollapsedHeaderStyle}" CellStyle="{StaticResource NoBackgroundCellStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Width="32" Style="{DynamicResource NoBackgroundButtonStyle}">
<Image Source="/KillCardMain;component/Resources/Images/edit.png" Width="16"></Image>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Code behind
private void CheckedTest(object sender, RoutedEventArgs e) {
int index = deckGrid.SelectedIndex;
DataGridRow row = (DataGridRow)deckGrid.ItemContainerGenerator.ContainerFromIndex(index);
row.IsSelected = true;
}