I have a DataGridView, whose DataSource is a DataTable. The user is allowed to modify the values in one specific cell in each row. I am interested in getting an IEnumerable of objects represented by rows that have been modified by the user.
The form implements a property as follows:
public IEnumerable<Invoice> modifiedInvoiceRecords
{
get
{
DataRowCollection modifiedRows = ((DataTable)dataGridView_invoiceHistory.DataSource).GetChanges(DataRowState.Modified).Rows;
// iterate through the modified rows and yield return objects
}
}
This yields a
NullReferenceException
Debugging shows that the modifiedRows variable is always null. Why is this so?