我有一个用它来插入数据的表单(Form2),该数据以另一种形式(form1)存在的组合框中显示,我想在插入form2后刷新该组合框
这是我的代码(form1)
private void button1_Click(object sender, EventArgs e)
{
string libelle = textBox1.Text;
string cause = textBox2.Text;
string interval = textBox3.Text +'-'+ textBox4.Text;
d.open();
int c = d.InsertPanne(libelle, cause, interval);
if (c == 1)
{
MessageBox.Show("Panne ajoutée avec succès");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
Form1 f = new Form1();
f.Refresh();
}
d.close();
}
Form1代码:
public partial class Form1 : Form
{
add_panne p = new add_panne();
DAO d = new DAO();
public Form1()
{
InitializeComponent();
List<panne> liste1 = d.getPannes();
comboBox3.DataSource = new BindingSource(liste1,null);
comboBox3.DisplayMember = "nompan";
comboBox3.ValueMember = "numpan";
comboBox3.SelectedIndex = -1;
}
}
答案 0 :(得分:0)
答案 1 :(得分:0)
克里特岛新功能,例如UpdateFormsControl 强>
private void UpdateFormsControls()
{
List<panne> liste1 = d.getPannes();
comboBox3.DataSource = null;
comboBox3.DataSource = liste1 ;
comboBox3.DisplayMember = "nompan";
comboBox3.ValueMember = "numpan";
comboBox3.SelectedIndex = -1;
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
}
只需将此功能调用为刷新组合框的项目......
private void button1_Click(object sender, EventArgs e)
{
string libelle = textBox1.Text;
string cause = textBox2.Text;
string interval = textBox3.Text +'-'+ textBox4.Text;
d.open();
int c = d.InsertPanne(libelle, cause, interval);
if (c == 1)
{
MessageBox.Show("Panne ajoutée avec succès");
//Call Update function to update values
UpdateFormsControls();
Form1 f = new Form1();
f.Refresh();
}
d.close();
}