Reputation: 583
I am trying to update a datagridview on my 'switchboard' to solve a concurrency issue. The switchboard has many checkboxes to check off when certain processes are done. When I click a checkbox on a record that has been edited I get a concurrency error as the dgv is not up to date.
I tried doing this:
How to refresh datagridview when closing child form?
to no avail as it raises other errors throughout my project.
Any help on how to refresh my datagridview on my switchboard on the form closing of another form would be great.
Thanks
public partial class frmSwitch : Form
{
public frmSwitch()
{
//'add a label and a buttom to form
InitializeComponent();
}
public void PerformRefresh()
{
this.propertyInformationBindingSource.EndEdit();
this.propertyInformationTableAdapter.Fill(this.newCityCollectionDataSet.PropertyInformation);
this.propertyInformationDataGridView.Refresh() }
}
public partial class frmSummary : Form
{
frmSwitch _owner;
public frmSummary(frmSwitch owner)
//public frmSummary()
{
InitializeComponent();
_owner = owner;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmSummary_FormClosing);
}
private void frmSummary_FormClosing(object sender, FormClosingEventArgs e)
{
_owner.PerformRefresh();
}
That is what I attempted to do but it caused issues in other instances when I needed to open Form2. The issue specifically occurs in the original opening of form 2 which is as follows:
private void propertyInformationDataGridView_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
System.Data.DataRowView SelectedRowView;
newCityCollectionDataSet.PropertyInformationRow SelectedRow;
SelectedRowView = (System.Data.DataRowView)propertyInformationBindingSource.Current;
SelectedRow = (newCityCollectionDataSet.PropertyInformationRow)SelectedRowView.Row;
frmSummary SummaryForm = new frmSummary();
SummaryForm.LoadCaseNumberKey(SelectedRow.CaseNumberKey, true, null);
SummaryForm.Show();
}
Upvotes: 1
Views: 6307
Reputation: 16757
It sounds like you are trying to create a new instance of your Switchboard form instead of modifying the existing instance of the form. When you open a form from the switchboard, I would suggest passing in instance reference to the switchboard form. Then, when you close the opened form, in your form_closing event you would refer to the passed in instance as the Switchboard form to update.
This method and others are specified in this article:
http://colinmackay.co.uk/blog/2005/04/22/passing-values-between-forms-in-net/
Upvotes: 3