A
A
Anton_repr2019-11-06 18:34:27
WPF
Anton_repr, 2019-11-06 18:34:27

How to update the contents of a DataGrid?

Adding items to the DataGrid:

private void addproduct_click(object sender, RoutedEventArgs e)
        {

            string sqlcom = $"INSERT INTO ingredientdata (name, year) VALUES ('{tb2.Text}','{tb1.Text}')";
            if (connectToDB.Connect())
            {
                using (MySqlCommand command = new MySqlCommand(sqlcom, connectToDB.connection))
                    command.ExecuteNonQuery();
                connectToDB.CloseConnect();
                MessageBox.Show("Сохранилось");

            }
        }

It was added to the database, and appears in the DataGrid only after the application is restarted

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2019-12-23
@Jewish_Cat

datagrid.Items.Refresh();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question