从另一个更新 WPF window(不是 MainWindow)中的数据网格。 *不使用 MVVM*
Update datagrid in WPF window (not MainWindow) from another one. *Without using MVVM*
我有一个 Window1,其中包含一个数据网格,当加载 Window1 时,该数据网格填充了 MYSQL 数据库,但是更新 Window2,其中包含文本框,以便将新信息保存在 MYSQL 数据库中。
我可以在打开和关闭 Window2 后更新信息,如下所示:
Window2.ShowDialog();
//refreshing datagrid
Mouse.OverrideCursor = System.Windows.Input.Cursors.AppStarting;
dtCustomers = AdminDB.Get_Table("SELECT id, name FROM engcustomers", db.MySqlCon);
dataGrid.DataContext = dtCustomers;
MessageBox.Show("The information has been updated correctly");
Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
这很完美,问题出现在 Window2 我按下按钮 "Cancel" 因为我不想更新任何东西,但由于我的代码,无论如何都会执行查询。
这就是为什么我需要你的 support/help 从 Window2.
更新 Window1 中的数据网格
你能帮帮我吗?
提前谢谢你们!
ShowDialog()
方法returns一个bool?
可以在Window2
关闭前设置,然后用[=14=判断操作是否被取消Window1
:
bool? cancelled = Window2.ShowDialog();
if (cancelled != true)
{
//refreshing datagrid
Mouse.OverrideCursor = System.Windows.Input.Cursors.AppStarting;
dtCustomers = AdminDB.Get_Table("SELECT id, name FROM engcustomers", db.MySqlCon);
dataGrid.DataContext = dtCustomers;
MessageBox.Show("The information has been updated correctly");
Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
}
窗口 2:
private void Cancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
Close();
}
我有一个 Window1,其中包含一个数据网格,当加载 Window1 时,该数据网格填充了 MYSQL 数据库,但是更新 Window2,其中包含文本框,以便将新信息保存在 MYSQL 数据库中。 我可以在打开和关闭 Window2 后更新信息,如下所示:
Window2.ShowDialog();
//refreshing datagrid
Mouse.OverrideCursor = System.Windows.Input.Cursors.AppStarting;
dtCustomers = AdminDB.Get_Table("SELECT id, name FROM engcustomers", db.MySqlCon);
dataGrid.DataContext = dtCustomers;
MessageBox.Show("The information has been updated correctly");
Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
这很完美,问题出现在 Window2 我按下按钮 "Cancel" 因为我不想更新任何东西,但由于我的代码,无论如何都会执行查询。 这就是为什么我需要你的 support/help 从 Window2.
更新 Window1 中的数据网格你能帮帮我吗?
提前谢谢你们!
ShowDialog()
方法returns一个bool?
可以在Window2
关闭前设置,然后用[=14=判断操作是否被取消Window1
:
bool? cancelled = Window2.ShowDialog();
if (cancelled != true)
{
//refreshing datagrid
Mouse.OverrideCursor = System.Windows.Input.Cursors.AppStarting;
dtCustomers = AdminDB.Get_Table("SELECT id, name FROM engcustomers", db.MySqlCon);
dataGrid.DataContext = dtCustomers;
MessageBox.Show("The information has been updated correctly");
Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
}
窗口 2:
private void Cancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
Close();
}