Question refreshing dgv, have tried everything

jamie123

Well-known member
Joined
May 30, 2008
Messages
82
Programming Experience
Beginner
Hello, I have a windows forms app on vs2008 and I am currently trying to refresh the datagridview after an insert() command. By refresh I mean reflect new changes. I have tried everything I've read online. Nothing seems to work. Please post any thoughts, here is my code:

FinancialTableAdapter.Insert(Form1.intPID, DateTimePicker1.Value, cboDesc.Text, txtCPT.Text, txtMOD1.Text, txtMOD2.Text, txtPay.Text, txtFee.Text, Balance, False, False)
Form1.DataGridView1.EndEdit()
FinancialBindingSource.EndEdit()
FinancialTableAdapter.FillByintPID(EbtblsDataSet.Financial, Form1.intPID)
Form1.DataGridView1.DataSource = Nothing
Form1.DataGridView1.DataSource = EbtblsDataSet.Financial
Form1.DataGridView1.Refresh()
FinancialBindingSource.ResetBindings(False)
Form1.DataGridView1.Parent.Refresh()
Form1.DataGridView1.Refresh()

*What I have now does work, but since the datasource for dgv1 should be the binding source (i think?) when i make changes in the datagrid, they do not save like they're supposed to (this is when i'm editing things in the datagrid, NOT when i'm inserting new rows), when i remove this code everything saves as it should, but after inserting new data the datagrid does not refresh.


Datagridview1 is my datagrid that is not refreshing
FinancialBindingSource is its datasource
EbtblsDataSet is my dataset that the bindingsource and tableadapter are both apart of
EbtblsDataSet.Financial is the financial table that is reflected by the FinancialTableAdapter and FinancialBindingSource
This insertion appears on a separate form than the datagridview

Again, the way up there works but it does not work correctly, it will not save updated changes right when I do other things on the datagridview, so I do not want to reload the source like I have it up there

If I didn't provide enough info please let me know and i'll clarify on whatever else

Thanks for your help in advance!
 
Doing some research on my own, i found out the answer to my own question, and i feel like this is a simple problem that is not answered well enough, as I must have searched 20 sites and no one could tell me an answer as simple as this:

If you are using table adapters and such to fill your datagrid, simply fill your table adapter again on the SAME FORM as your datagridview. I had a tableadapter.fill() command on another form, and this is why it never refreshed, resetting the source to the datagridview can cause problems as it did for me, i recommend all having trouble with refreshing datagridviews put their fill command in the same form as their datagridview.

I put this fill command in a public subroutine I called UpdateGrid() on my form1, everytime I need to refresh the datagridview I call "Form1.UpdateGrid()"

hope this helps others!
 
Back
Top