Handy Control DataGrid 全选
提问
如何实现Handy Control DataGrid 全选
回答
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
if (((sender as CheckBox)!).IsChecked!.Value)
foreach (var item in ((grid1.DataContext as TrendDataSyncDialogViewModel)!).TrendTagCollection)
item.IsSelected = true;
else
foreach (var item in ((grid1.DataContext as TrendDataSyncDialogViewModel)!).TrendTagCollection)
item.IsSelected = false;
}
<DataGrid Name="grid1" Grid.Row="1" hc:DataGridAttach.ShowRowNumber="True" hc:DataGridAttach.CanUnselectAllWithBlankArea="True" HeadersVisibility="All" RowHeaderWidth="60" AutoGenerateColumns="False" ItemsSource="{Binding TrendTagCollection}">
<DataGrid.Columns>
<DataGridCheckBoxColumn Width="80" CanUserResize="False" Binding="{Binding IsSelected}" >
<DataGridColumn.Header >
<CheckBox Name="CheckAll" Content="全选" Unchecked="ButtonBase_OnClick" Checked="ButtonBase_OnClick" ></CheckBox>
</DataGridColumn.Header>
</DataGridCheckBoxColumn>
<DataGridTextColumn IsReadOnly="True" Width="180" CanUserResize="False" Binding="{Binding xxx}" Header="xxx"/>
<DataGridTextColumn IsReadOnly="True" Width="*" CanUserResize="False" Binding="{Binding xxx}" Header="xxx"/>
<DataGridTextColumn IsReadOnly="True" Width="80" CanUserResize="False" Binding="{Binding xxx}" Header="xxx"/>
<DataGridTextColumn IsReadOnly="True" Width="80" CanUserResize="False" Binding="{Binding xxx}" Header="xxx"/>
</DataGrid.Columns>
</DataGrid>