if add row to DataTable
DataRow row = datatable1.NewRow();
row[\"column2\"]=\"column2\";
row[\"column6\"]=\"column6\";
datatable1.Rows.Add(row);
If you´ve already defined a DataSource
, You can get the DataGridView
´s DataSource
and cast it as a Datatable
.
Then add a new DataRow
and set the Fields Values.
Add the new row to the DataTable
and Accept the changes.
In C# it would be something like this..
DataTable dataTable = (DataTable)dataGridView.DataSource;
DataRow drToAdd = dataTable.NewRow();
drToAdd["Field1"] = "Value1";
drToAdd["Field2"] = "Value2";
dataTable.Rows.Add(drToAdd);
dataTable.AcceptChanges();