'Identify changed rows in datagridview control

How do I loop through a datagridview control (windows forms) and determine which rows have been edited, deleted or are new?

foreach (DataGridViewRow dgvr in dgv_OtherEarnings.Rows)
{

}


Solution 1:[1]

No matter what kind of loop but you have to know is ..

DataGridView.NewRowIndex will get the index of the row for new record

DataGridView.IsCurrentRowDirty will indicating wether the current row has uncomitted changes

Solution 2:[2]

This is really old but if it helps anyone...if your datagridview is based on a datatable you can iterate through the changed rows using

DataTable changes = datatableyourgridisbasedon.GetChanges();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 matzone
Solution 2 MX313