1

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();



}
Community
  • 1
  • 1
korrowan
  • 563
  • 2
  • 15
  • 37

1 Answers1

3

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/

Colin Mackay
  • 18,736
  • 7
  • 61
  • 88
IAmTimCorey
  • 16,412
  • 5
  • 39
  • 75
  • 1
    @korrowan - Not sure what you mean but basically, these methods could update your datagrid and kick off the refresh method on your form so you don't get that (or other) errors – IAmTimCorey May 15 '11 at 23:27
  • @BiggsTRC I believe that is the same thing as what I already did unless I am confused... my original post is updated with the code that I used. – korrowan May 15 '11 at 23:27
  • @korrowan - Does the update work if you manually run it on your switchboard? What I am asking is does this method `PerformRefresh` work at all? Have you tried adding a new button on your switchboard (`Form1`) that kicks off the method `PerformRefresh` and click it after you close out `Form2`? – IAmTimCorey May 15 '11 at 23:37
  • @BiggsTRC no I have not but I will do that. Here is the error that I get when I do during form closing event: Error 1 'CityCollectionCSharp.frmSummary' does not contain a constructor that takes 0 arguments – korrowan May 15 '11 at 23:40
  • @BiggsTRC and that occurs here frmSummary SummaryForm = new frmSummary(); SummaryForm.LoadCaseNumberKey(SelectedRow.CaseNumberKey, true, null); SummaryForm.Show() when trying to call frmSummary – korrowan May 15 '11 at 23:46
  • @korrowan - it is getting a bit difficult to follow since your example above uses Form1 and Form2 and now you are using different names. However, if frmSummary is your "child" form (not in the MDI sense, just in terms of who opened who), the issue is that you aren't passing in an instance of your parent form when you open the child. You have to open it like so: `frmSummary SummaryForm = new frmSummary(this);` since you require the initiating form instance be a parameter for opening your child form. – IAmTimCorey May 15 '11 at 23:50
  • @BiggsTRC OIC how it works now thank you soo much..it works perfectly! I did not know to the THIS and that is where I went wrong! – korrowan May 15 '11 at 23:52