0

Possible Duplicate:
simple DataGridView refresh question

I have a mainForm which has a DataGridView which has a bunch of databound items from a List. From there I can edit a selected row in the DataGridView (and the list obviously) by opening up a new form and changing the content using text boxes and such. The editing is working fine, however, once I close the edit form, the datagridview is not refreshing? In order to view the updated items I have to reload the items from the list.

At the moment I'm doing this in the edit form during the exit button click event but to no avail:

            MessageBox.Show("Client successfully edited");            
            mForm.DataGridViewProp.EndEdit(); //dgv property within the mForm
            mForm.DataGridViewProp.Refresh(); //dgv property within the mForm
            mForm.DataPanel.Invalidate(); //the panel the dgv is in
            mForm.DataPanel.Refresh(); //the panel the dgv is in
            this.Close();

Where mForm is an instance of the main form:

            private mainForm mForm = new mainForm();

I repeat, the edit is working 100% fine, it's simply not refreshing the DGV.

Any help is greatly appreciated.

Thanks

Community
  • 1
  • 1
Ari
  • 1,026
  • 6
  • 20
  • 31

2 Answers2

0

I think You need to bind the gridview after changing it.

Hiren
  • 1,381
  • 5
  • 24
  • 41
  • That's what I thought too. I know it definitely has something to do with that, because when I rebind the data in the mainform, it works fine. I think the problem lies somewhere between using two forms, and more specifically, refreshing the the dgv from the edit form. – Ari Dec 02 '11 at 23:28
  • May be you can add button call CLOSE in another form and on that button click you can bind the gridview again... – Hiren Dec 03 '11 at 00:34
0

Does the datasource that is bound to the grid support property change notification? If not, then you will need to let the grid know through the appropriate mechanism, that the record has changed.

competent_tech
  • 44,465
  • 11
  • 90
  • 113