I have a form which contains a button and a DataGridView.
The button allows me to add a new person to the database :
DataRow drow = sql.ds.Tables["Etablissement"].NewRow();
drow[1] = nom.Text; //drow[0] it's an auto-countign var
drow[2] = string.IsNullOrEmpty(ville.Text) ? DBNull.Value : (object)ville.Text;
sql.ds.Tables["Etablissement"].Rows.Add(drow);
SqlCommandBuilder cmb = new SqlCommandBuilder(daEtablissement);
daEtablissement.Update(sql.ds, "Etablissement");
dgv.Refresh(); // dgv : DataGridView that i'm usign
XtraMessageBox.Show("Bien Ajouter !");
Videz();
nom.Focus();
the problem is when the DataGridView is refreshed the code of the person I added doesn’t display, how can I solve this?
The Refresh method is just a UI refresh and not data binding refresh. The best and simple way is to use a
BindingSourcewhich has yourDataTableas a data source, and theBindingSourceis set as the data source of the grid. Usually when you update theDataTable, the grid should show the new data, but if it doesn’t happen you can callBindingSource.ResetBindings(false)Code:
If for any reason updating the data table does not refresh the grid you can call: