WPF DataGrid-我想知道用户何时输入新行
我有两个DataGrid,我想知道用户何时输入新行,以检查他是否已经在另一个DataGrid中选择了行。如果他没有选择,则拒绝新行 此代码u可由dataGrid中的事件RowEditEnding使用,方法是检查行是否为NewItem:WPF DataGrid-我想知道用户何时输入新行,wpf,datagrid,row,Wpf,Datagrid,Row,我有两个DataGrid,我想知道用户何时输入新行,以检查他是否已经在另一个DataGrid中选择了行。如果他没有选择,则拒绝新行 此代码u可由dataGrid中的事件RowEditEnding使用,方法是检查行是否为NewItem: private void dataGrid1_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { if (e.Row.IsNewItem) {
private void dataGrid1_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
if (e.Row.IsNewItem)
{
// here check if dataGrid2 have been selected row
if (dataGrid2.SelectedItem == null)
{
MessageBox.Show("you have not Selected Vehicle,Please try again", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
// here rebind dataGrid1 to clear new row
dataGrid1.ItemsSource = salesData.T_Services.Where(x => x.FileNo == tbFileNo.Text);
return;
}
}
}
当我有这个问题时,我在任何地方都找不到答案,我的研究持续了很长时间。所以我想把问题放在这里。也许我得到了答案,但我想得很好后就知道了答案,所以我很快就给出了答案,没有解释。对此我很抱歉,我很高兴这段代码解决了这个问题。