I have a datagrid view that is bind to a custom collection. I have add remove options in the UI which will add and delete a row in datagridview.
Is there any way to get newly added rows in datagridview?
I have a datagrid view that is bind to a custom collection. I have add remove options in the UI which will add and delete a row in datagridview.
Is there any way to get newly added rows in datagridview?
The DataGridView has a RowAdded event that gets triggered every time a Row is added (duh!). The Event args is of type: DataGridViewRowsAddedEventArgs which has a RowIndex property on it which enables you to do something like this:
public Form1()
{
InitializeComponent();
this.dataGridView1.RowsAdded += new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
}
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
DataGridViewRow newRow = this.dataGridView1.Rows[e.RowIndex];
}