[英]How Can i Call Form1 load event from from Form2 button click event
I have a two simple windows form:FormA and FormB. 我有两个简单的Windows窗体:FormA和FormB。
in my FormA has a simple datagridView And i show the my simple table information,i use the this code to show the my information in FormA load event: 在我的FormA中有一个简单的datagridView并且我显示了我的简单表信息,我使用以下代码在FormA加载事件中显示了我的信息:
string selectcommand = "select *from WhiteList";
SqlCeConnection connection = new SqlCeConnection(conString);
SqlCeDataAdapter adaptor = new SqlCeDataAdapter(selectcommand, conString);
DataSet ds = new DataSet();
adaptor.Fill(ds, "test");
DataTable table = ds.Tables["test"];
dataGridView1.DataSource = table;
when the information show in datagridView and when user click on gridView Row,Open FormB and show the DatagridView fields in FormB textBox,in FormB i use this code: 当信息显示在datagridView中,并且当用户单击gridView Row时,打开FormB并在FormB文本框中显示DatagridView字段,在FormB中,我使用以下代码:
SqlCeConnection connection = new SqlCeConnection(conString);
connection.Open();
SqlCeCommand cmd = new SqlCeCommand("Update WhiteList set Name=@behi,Count=@rezi where id=@rezii", connection);
cmd.Parameters.AddWithValue("@behi", textBox1.Text);
cmd.Parameters.AddWithValue("@rezi", Convert.ToInt32(textBox2.Text));
cmd.Parameters.AddWithValue("@rezii", Convert.ToInt32(label1.Text));
cmd.ExecuteNonQuery();
to Update the my simple table,But I want when click the Update Button on the FormB,in FormA datagridView refresh,How can i do this? 更新我的简单表格,但是我想在FormB的datagridView刷新中单击FormB上的“更新”按钮时,该怎么做?
public partial class FirstForm: Form
{
public FirstForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SecondForm form2 = new SecondForm (this);
SecondForm .Show();
}
public void UpdateDataGrid()
{
//add your code here
}
}
public partial class SecondForm : Form
{
private FirstForm form1;
public SecondForm ()
{
InitializeComponent();
}
public SecondForm (FirstForm form1)
: this()
{
this.form1 = form1;
}
private void button1_Click(object sender, EventArgs e)
{
form1.UpdateDataGrid();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.