C# – Return only the changed rows of a datagridview

cdatagridviewwinforms

I have a winform that contains a datagridview. The form is totally disconnected from the data. The codebehind calls a webservice, which returns a table. That table becomes the datasource for the datagridview. Once the datagridview is displayed, a user can edit whichever rows they desire. Currently, when they hit the 'Update' button, every row in the grid is returned.

Is there a way to return only the changed rows in the datagridview?

UPDATE: Based off Tezzo's answer below, I was able to do this:

var changedRows = ((DataTable)dataGridView1.DataSource).GetChanges(DataRowState.Modified).Rows;

Best Answer

You can retrieve changes in a DataTable using GetChanges.

So you can use this code with a DataGridView:

CType(YourDataGridView.DataSource, DataTable).GetChanges(DataRowState.Modified).Rows