This is my code:
private void button1_Click(object sender, EventArgs e)
{
DataTable table = new DataTable();
using (SqlCeDataAdapter sqlCeDataAdapter = new SqlCeDataAdapter("SELECT * FROM test", sqlCeConnection))
{
sqlCeDataAdapter.Fill(table);
}
dataGridView1.DataSource = table;
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show(((DataTable)dataGridView1.DataSource).Rows.Count.ToString());
}
What I'm trying to do is to update the underlying database, but according to this tutorial, the underlying DataTable would need to reflect the changes made on the DataGridView whenever I edit the rows. What I'm doing is just running the app, pressing button1, then deleting some rows in the DataGridView and then pressing button2 to see how many rows I get. On this app I get the same amount of rows as before deleting rows, but if I replace dataGridView1's DataSource with a DataTable that I populate myself (By calling DataTable.NewRow() and so on), the changes are reflected on the DataTable every time I delete a row (the underlying DataTable contains less rows after I delete some of them).