Link to home
Start Free TrialLog in
Avatar of rrmart
rrmart

asked on

Refresh DataGridView

I am trying to refresh a DataGridView with a bindingsouce to an Access table.  The table is changed and my DataGridView is not reflecting the changes.

I've tried:

dgv.Refresh();

If I exit the form and restart, then I can see the changes in the table in the DataGridView.

How do I tell the DataGridView to refresh as I change the table?
Avatar of AUmidh
AUmidh

You have to get the data and then refresh datagridview
Avatar of rrmart

ASKER

Thanks for the reply AUmidh.  What exactly do you mean by "get"?  

I can see the original table data in the DataGridView fine when the form loads.  Then I change the table in the code behind the form, but don't see these changes when done.

SOLUTION
Avatar of Aleksei_Malkov
Aleksei_Malkov
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@rrmart:
Recall the procedure which you implement on form load before dgv.Refresh();
Avatar of rrmart

ASKER

I tried:

                dgv.DataSource = null;
                dgv.DataSource = dgBindingSource;
                dgv.Refresh();

This did not work either.  Hm-m-m-m  I noticed though, that this caused the first two columns in the DataGridView to go blank (ID (primary key), and the next field).

Thanks for the idea, though.

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rrmart

ASKER

Thanks abel.  I still cannot get this to work.  I suspect my bindingsource is not what I think it is:

Tried:
bindingSource1.DataSource = propertyDBDataSet3._InventoryTempTable;
dgv.DataSource = bindingSource1;

In Design View I can preview bindingSource1 and the data shows correctly.

Is there a DataGridView property setting I'm missing?  (I've cleared the DataGridView and started over numerous times now.)
Did you try bindingSource1.ResetBindings()? What is the class type of the binding source?
Avatar of rrmart

ASKER

Yes I tried:

bindingSource1.ResetBindings(false);   //  Also tried true (not changing schema though)

bindingSource1.DataSource = propertyDBDataSet3._InventoryTempTable;
dgv.DataSource = bindingSource1;

The class type of my bindingSource1 is:

System.Windows.Forms.BindingSource


Thanks abel for hanging in here with me.   . . .
Avatar of rrmart

ASKER

I finally solved this:

gdv.DataSource = bindingSource1;
                _InventoryTempTableAdapter.Fill(this.propertyDBDataSet3._InventoryTemp);

Where propertyDBDataSet3 ==> DataSet
_InventoryTemp                    ==> Datamember

I had to refill the table adapter.  Not sure why but it worked.
Avatar of rrmart

ASKER

Your comment lead me to investigate DataSet and Tableadapters I was using and declaring at form load time.
I will remember that solution, thanks for pointing that out. For asp.net, I knew that (and it has Rebind method), I thought it wasn't necessary on WinForms. Glad you found your solution in the end. ;-)