smaguire
asked on
Refreshing DataGridView Control
hi all,
I have a DataGridView Control that is bound to a dataset and the ds linked to a stored procedure
the DGV is placed in a tab control, whenever the user clicks that tab, I call the following method:
private void InitializeDisplaySettingsG rid()
{
dgvDisplaySettings.DataSou rce = null;
dgvDisplaySettings.DataSou rce = ds.CustomDisplaySettings.D efaultView ;
}
it works and show data just fine, but if I change anything in the table (from the database or from the application) the new modified data will not show until the I stop and restart the application.
I tried to use dgvDisplaySettings.Refresh () but didn't help, I also tried manually as you can see from the code above to set the datasource to null and then call it again, without any luck
Why can't I get it to show the modified data IF i am binding it to the datasource everytime the user selects that tab page?
I am using windows forms, and visual studio 2008
thanks
I have a DataGridView Control that is bound to a dataset and the ds linked to a stored procedure
the DGV is placed in a tab control, whenever the user clicks that tab, I call the following method:
private void InitializeDisplaySettingsG
{
dgvDisplaySettings.DataSou
dgvDisplaySettings.DataSou
}
it works and show data just fine, but if I change anything in the table (from the database or from the application) the new modified data will not show until the I stop and restart the application.
I tried to use dgvDisplaySettings.Refresh
Why can't I get it to show the modified data IF i am binding it to the datasource everytime the user selects that tab page?
I am using windows forms, and visual studio 2008
thanks
ASKER
No DataBind() property in windows form
Ah. In that case call Refresh in the DataBindingComplete event
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
dataGridView1.Refresh();
}
ASKER
Thanks ororiole for your reply,
I've tried that and still does not work. I can verify data being changed in the database but will not show in the grid until i restart the app
thanks
I've tried that and still does not work. I can verify data being changed in the database but will not show in the grid until i restart the app
thanks
SEt a breakpoint in the DAtaBindComplete event handler to make sure it is bering raised. Then take a look at the DataBindingCompelteEventAr gs to see if the CompleteState is Success and/or what ErrorText may be.
Make sure you are reloading your dataset/datatable when the database changes.
Make sure you are reloading your dataset/datatable when the database changes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
dgvDisplaySettings.DataSou
dgvDisplaySettings.DataBin
Binding doesnt actually occur until the DataBind event, which you can ensure by calling DataBind() anytime your datasource changes. If your database table changes, you are going to need to go get it again and update your datatable. (At least, thats the basic way)