dotnetmonitor.com

 
Index
Previous
Next

 

The row for new records is contained in the DataGridView control's Rows collection, so the following line returns the new row:

DataGridViewRow row = dataGridView1.Rows[dataGridView1.Rows.Count - 1];

 

Even though the new row is in the rows collection it does behaves differently in two respects:

 

  • The row for new records cannot be removed from the Rows collection programmatically. An InvalidOperationException is thrown if this is attempted. The user also cannot delete the row for new records. The DataGridViewRowCollection.Clear method does not remove this row from the Rows collection.

 

  • No row can be added after the row for new records. An InvalidOperationException is raised if this is attempted. As a result, the row for new records is always the last row in the DataGridView control. The methods on DataGridViewRowCollection that add rowsAdd, AddCopy, and AddCopiesall call insertion methods internally when the row for new records is present.
What is the DataGridView
Differences between the DataGridView and DataGrid controls
Highlight of features
Structure of DGV
Architecture Elements
Cells and Bands