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?
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?
You have to get the data and then refresh datagridview
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@rrmart:
Recall the procedure which you implement on form load before dgv.Refresh();
Recall the procedure which you implement on form load before dgv.Refresh();
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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._Invent oryTempTab le;
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.)
Tried:
bindingSource1.DataSource = propertyDBDataSet3._Invent
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.ResetBindin gs()? What is the class type of the binding source?
ASKER
Yes I tried:
bindingSource1.ResetBindin gs(false); // Also tried true (not changing schema though)
bindingSource1.DataSource = propertyDBDataSet3._Invent oryTempTab le;
dgv.DataSource = bindingSource1;
The class type of my bindingSource1 is:
System.Windows.Forms.Bindi ngSource
Thanks abel for hanging in here with me. . . .
bindingSource1.ResetBindin
bindingSource1.DataSource = propertyDBDataSet3._Invent
dgv.DataSource = bindingSource1;
The class type of my bindingSource1 is:
System.Windows.Forms.Bindi
Thanks abel for hanging in here with me. . . .
ASKER
I finally solved this:
gdv.DataSource = bindingSource1;
_InventoryTempTableAdapter .Fill(this .propertyD BDataSet3. _Inventory Temp);
Where propertyDBDataSet3 ==> DataSet
_InventoryTemp ==> Datamember
I had to refill the table adapter. Not sure why but it worked.
gdv.DataSource = bindingSource1;
_InventoryTempTableAdapter
Where propertyDBDataSet3 ==> DataSet
_InventoryTemp ==> Datamember
I had to refill the table adapter. Not sure why but it worked.
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. ;-)