[英]Refresh datagridview records from another form
I have dataGridView1
in form1
but for inserting in it I'm using form2
which have save button (that provides insert into datagridview1) to which I'm trying to set - refresh
or select * from
so I dont need any refresh button in form1
whenever I want to show up just all the recors. 我在form1
有dataGridView1
,但是要在其中插入,我使用的是form2
,它具有要设置的保存按钮(可将其插入到datagridview1中)- refresh
或select * from
因此无论何时我在form1
都不需要任何刷新按钮我只想露面所有的演奏者。 Is there any way to achieve that? 有什么办法可以实现?
Thanks much for your time. 非常感谢您的宝贵时间。
You can use delegate.. For example : 您可以使用委托。.例如:
Form1 : 表格1:
private void btnForm1_Click(object sender, System.EventArgs e)
{
// Create an instance of form 2
Form2 form2 = new Form2();
// Create an instance of the delegate
form2.passControl = new Form2.PassControl(PassData);
// Show form 2
form2.Show();
}
private void PassData(object sender)
{
// Set de text of the textbox to the value of the textbox of form 2
txtForm1.Text = ((TextBox)sender).Text;
}
Form 2 : 表格2:
public class Form2 : System.Windows.Forms.Form
{
// Define delegate
public delegate void PassControl(object sender);
// Create instance (null)
public PassControl passControl;
private void btnForm2_Click(object sender, System.EventArgs e)
{
if (passControl != null)
{
passControl(txtForm2);
{
this.Hide();
}
}
I hope this helps.. 我希望这有帮助..
You can use Form.DialogResult
to achieve this. 您可以使用Form.DialogResult
来实现。
In your insert form, after saving data to database: 将数据保存到数据库后,以插入形式:
DbContext.SaveChanges();
MessageBox.Show("Successfully saved.");
DialogResult = System.Windows.Forms.DialogResult.Yes;
and In your grid form: 并在您的网格形式中:
Frm_NewData newData = new Frm_NewData();
if (newData.ShowDialog() == System.Windows.Forms.DialogResult.Yes)
{
RefreshGrid();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.