I add the data. Data is added, but the changes are not displayed in the DataGridView . Only displayed when the program is restarted.

  DataRow newContactRow = fr1.zooparkDataSet.Tables["Animal"].NewRow(); newContactRow["Name"] = textBox1.Text; newContactRow["ID_Klass_zver"] = selectedItem1.ToString(); newContactRow["ID_Tip_zver"] = selectedItem2.ToString(); newContactRow["ID_Korm_zver"] = selectedItem3.ToString(); fr1.zooparkDataSet.Tables["Animal"].Rows.Add(newContactRow); fr1.animalTableAdapter.Update(fr1.zooparkDataSet.Animal); fr1.animalTableAdapter.Fill(fr1.zooparkDataSet.Animal); fr1.animalDataGridView.Refresh(); 
  • And on what event do you have an update? - Sv__t
  • @Sv_t, I try to update with the last two lines - user248223
  • I understood it. I mean, when do you add a string? Filled in the fields, and then what? Have you pressed a button? - Sv__t
  • Yes, all this happens in a button event (when you click on it) - user248223
  • The Refresh method does not cause data update (rebinding)! It causes the drawing of the surface, i.e. in fact, it generates a Paint event. In this case, it is useless, remove his call. - Alexander Petrov

2 answers 2

Try reassigning the DataSource :

 fr1.animalDataGridView.DataSource = null; fr1.animalDataGridView.DataSource = fr1.zooparkDataSet.Tables["Animal"]; 

To prevent automatic generation of grid fields, AutoGenerateColumns = false value of the AutoGenerateColumns = false property to AutoGenerateColumns = false :

 fr1.animalDataGridView.AutoGenerateColumns = false; 

    Use BindingList<T> like this:

     var data = new BindingList<object>(); fr1.animalDataGridView.DataSource = data; data.Add(item1); data.Add(item2); 

    When adding items, the DataGridView will update itself.