如何知道用户是否已选择或取消选择DataGrid的所有行? [英] How do I know if the user has selected or deselected all rows of the DataGrid ?
本文介绍了如何知道用户是否已选择或取消选择DataGrid的所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的DataGrid,我怎么知道用户是否选择或取消选择了DataGrid的所有行?
谢谢
This is my DataGrid, how do I know if the user has selected or deselected all rows of the DataGrid ?
Thanks
<DataGrid ItemsSource="{Binding Dati_Viag}" SelectedItem="{Binding SelectDat}" Style="{DynamicResource ST_DataGrid}"
CellStyle="{DynamicResource St_DataGridCellStyle}" SelectionMode="Extended" Name="Dg_Dati" >
<DataGrid.Columns>
<DataGridTextColumn x:Name="col_A" Binding="{Binding Path=A}" Header="A" Width="250" />
<DataGridTextColumn x:Name="col_U" Binding="{Binding Path=B}" Header="B" Width="250" />
<DataGridTextColumn x:Name="col_K" Binding="{Binding Path=C}" Header="C" Width="250" />
</DataGrid.Columns>
</DataGrid>
推荐答案
SelectionMode =扩展可以。您可以在DataGrid中的Selection_Changed事件中编写这行代码:
Hi,
SelectionMode="Extended" are OK there. You can write this line of code inside of your Selection_Changed event from the DataGrid:
private void Dg_Dati_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.Dg_Dati.SelectedItems != null) //Avoid exception
{
if (this.Dg_Dati.SelectedItems.Count == 0)
{
MessageBox.Show("The user has deselected all rows");
return;
}
if (this.Dg_Dati.SelectedItems.Count == this.Dg_Dati.Items.Count)
{
MessageBox.Show("The user has selected all rows");
return;
}
}
}
希望有所帮助。
Hope it helps.
这篇关于如何知道用户是否已选择或取消选择DataGrid的所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文