0
votes

I created a datagridview with a dataset as its data source. On the keydown event of a certain textbox i add a new line to the dataset and it is direclty reflected in the datagridview. But if i happen to click on the final row in the datagridview "the one with the star on its left" no matter how many lines i add to the dataset they wont be reflected. If i return the count of the dataset rows i can see that they are added only they are no more reflected in the datagridview. I tried ds.acceptchanges and datagridview.refresh but non helped. Any solution?

Here is the code i used:

if ds.tables(0).rows(datagridview.rows.count-1).item("Amount")<>0 then
ds.tables(0).rows.add(ds.tables(0).newrow)
end if
1

1 Answers

0
votes

OK, First of all, you should use a Binding Source. This is what makes your DataGridView & DataTable as one.

First Thing to do is this :-

BindingSource bs = new BindingSource();
bs.DataSource = ds.tables[0];

Now you need to setup the Datasource for your DatagridView, which will be your BindingSource bs :-

DatagridView1.Datasource = bs;

Now any changes made in your DatagridView will automatically reflect in your DataSet Table. It also means that any changes made in the DataTable will automatically reflect in your GridView.