In my parent form I have comboBox populated with items using DataTable
as DataSource
which looks like this.
sourceTypes = myDataBase.SourceType.ToList<SourceTypes>();
DataTable dt = new DataTable();
DataColumn dc1 = new DataColumn("Name");
DataColumn dc2 = new DataColumn("ID");
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
foreach (SourceType sourceType in sourceTypes)
{
string sourceTypeName = sourceType.sourceTypeName;
string ID = sourceType.sourceTypeID.ToString();
dt.Rows.Add(sourceTypeName, ID);
}
comboBox3.DataSource = dt;
comboBox3.ValueMember = "ID";
comboBox3.DisplayMember = "Name";
From my parent form I am calling my child form in which I add new record to myDataBase
and I would want this new added record to be visible in my parent's form comboBox as soon as child form is closed. So I was thinking to call something like this from my childFrm which will refresh the comboBox.
private void FrmChild_FormClosed(object sender, FormClosedEventArgs e)
{
FrmParent.refresh();
}
Now I need the static refresh method in my parent form, which I can't really get to work. How could I get it done? Cheers
EDIT: Child form is opened here:
private void button7_Click(object sender, EventArgs e)
{
FrmChild frmChild = new FrmChild();
frmChild.ShowDialog();
frmChild.Dispose();
}
EDIT2: I tried like this (no static method), but didn't work
In my Child form:
private void FrmChild_FormClosed(object sender, FormClosedEventArgs e)
{
FrmParent frmParent = new FrmParent();
frmParent.refresh();
}
In my parent form, refresh method (after the new record is added to myDataBase).
sourceTypes = myDataBase.SourceType.ToList<SourceTypes>();
DataTable dt = new DataTable();
DataColumn dc1 = new DataColumn("Name");
DataColumn dc2 = new DataColumn("ID");
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
foreach (SourceType sourceType in sourceTypes)
{
string sourceTypeName = sourceType.sourceTypeName;
string ID = sourceType.sourceTypeID.ToString();
dt.Rows.Add(sourceTypeName, ID);
}
comboBox3.DataSource = dt;
comboBox3.ValueMember = "ID";
comboBox3.DisplayMember = "Name";
Tried like this, combobox still doesnt get refreshed.