Update DataTable with DataGridView
-
Hi, I have a DataTable bound to a DataGridView with this code: dataGridView1.DataSource = myDT_Items; I'm updating a DataGridView with this code: dgvRow.Cells["ItemSize"].Value = 55; Now I want the DataTable to reflect the changes made to the DataGridView. Currently I'm using: myDT_Items.AcceptChanges(); Q: Is there another way to Synchronize DataTable with DataGridView when changes are made to the DataGridView? Thanks, Ron
-
Hi, I have a DataTable bound to a DataGridView with this code: dataGridView1.DataSource = myDT_Items; I'm updating a DataGridView with this code: dgvRow.Cells["ItemSize"].Value = 55; Now I want the DataTable to reflect the changes made to the DataGridView. Currently I'm using: myDT_Items.AcceptChanges(); Q: Is there another way to Synchronize DataTable with DataGridView when changes are made to the DataGridView? Thanks, Ron
-
Why are you using the synchronization? Are you using datagridview some where else as well? If not then do the changes directly in the datatable.
Ahsan Ullah Senior Software Engineer
Thanks Ahsan, Yes, I could update the DataTable directly, but then I'd have use something like dataTable.Rows.Find() to correlate with the selected row in DataGridView. Do you know of a better way to find the DataTable row based on the selected DataGridView Row? Even if I do go the route of updating the DataTable directly, I'm always interested in learning more. I'm basically wanting to know the best way to sync the DataTable with the DataGridView if the DataGridView is edited. Ron