0
Hello, I’m trying to select all Checkbox of a datagrid but I’m not succeeding.
Below is my code to select:
private void CheckUnCheckAll(object sender, RoutedEventArgs e)
{
CheckBox chkSelectAll = ((CheckBox)sender);
if (chkSelectAll.IsChecked == true)
{
dgUsers.Items.OfType<CheckBox>().ToList().ForEach(x => x.IsChecked = true);
}
else
{
dgUsers.Items.OfType<CheckBox>().ToList().ForEach(x => x.IsChecked = false);
}
}
Where dgUsers
is my Datagrid however I could notice that is not finding any checkbox inside the grid.
Below is my shampoo where creates the checkbox within the datagrid see that I invoke the function by clicking on the checkbox:
<DataGrid.Columns>
<DataGridCheckBoxColumn x:Name="col0" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}">
<DataGridCheckBoxColumn.HeaderTemplate>
<DataTemplate>
<CheckBox Click="CheckUnCheckAll" >
</CheckBox>
</DataTemplate>
</DataGridCheckBoxColumn.HeaderTemplate>
</DataGridCheckBoxColumn>
<DataGrid.Columns>
Here’s a grid image
What would be the correct way to select all the Checkboxes of a Datagrid?
or the element I want in the Checkbox case ?
– Marcos Brinner
if I’m not mistaken Checkbox, if you check the code is similar to what you already have currently just adapt
– Otto
Thanks after a search discover that where Yourclass is the Modelview that must be passed and isChecked is the name of the property that is defined in the modelview for the checkbox biding
– Marcos Brinner