[英]C# DataGridView refresh after insert
I have form A on which is DataGridView and a Button. 我有一个表格A,上面是DataGridView和一个Button。 After clicking a button, new form, form B opens.
单击按钮后,将打开新表格B表格。
On form B i have two textboxes and update button. 在表格B上,我有两个文本框和“更新”按钮。 On clicking that button data is inserted in database.
单击该按钮后,数据将插入数据库中。 And form B is closed.
并且表格B是关闭的。
How can I update DataGridView to get new data. 如何更新DataGridView以获取新数据。 It's not accesible from form B.
从表格B无法访问。
ShowDialog form B and Return DialogResult After InsertButton Click , Check After From b Call, if DialogResult is Yes Rebind DataGridView (RefreshBindings) ShowDialog窗体B并在InsertButton单击后返回DialogResult,从b调用后检查,如果DialogResult为Yes,则重新绑定DataGridView(RefreshBindings)
//in Form A
private void btnOpenFromB_Click(sender,event)
{
FormB B =new FormB();
if(B.ShowDialog()==DilogResult.Yes)
//Call RefreshMethod of DG
}
//In Form B
//in Constructor
public FromB()
{
initilizeComponents();
DialogResult=DialogResult.No;
}
//In Insert Button Click
private void InserClick(sender,event)
{
if(Checking()==true)
{
//Insert Operations
DialogResult=DilogResult.Yes;
this.Close();
}
}
hi Give the Form A in Form B constructor or add it after creating you need to update the grid before closing the Form. 嗨,在窗体B的构造函数中提供窗体A或在创建后添加窗体A,需要在关闭窗体之前更新网格。
Second way put the data in a field in Form A and than wait the Form B to be closed after closing update the grid. 第二种方式将数据放在Form A的字段中,然后在关闭更新网格之后等待Form B关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.