views:

267

answers:

1

Hi.In my WinApp I am using DataGridView in tab control.When I am adding to table in another tab ,it does not update datagridview. After closing and re-opening app it shows new value.I connected my table with wizard to datagridview. And in my Button action after adding new value to data base I used

this.BindingContext[this.dataGridView1.DataSource].EndCurrentEdit();
this.dataGridView1.Refresh();
this.dataGridView1.Parent.Refresh();

but it is not working.I am using mysql.

A: 

Calling "Refresh" won't help you because the DataSource on your DataGridView does not contain the new value (I'm guessing that your just persisting the new value added from the other tab directly to the db).

You have to do one of the following:

  1. Add new value to DataGridViews DataSource. If the DataSource is a BindingList, the grid will be automatically notified of the new value. If not, use a BindingSource and invoke "ResetBindings".

  2. Repopulate the DataGridView DataSource from the database.

I've never used the wizard you are talking about, but I'm guessing that it does not design code that goes directly to the database on every refresh to check for new values.

Marius