[RESOLVED] Iserting new row into Datagridview
Hello everybody,
I have unbounded datagridview, and I am using the next command to add new row:
Code:
tblResults.Rows.Add()
This command adds new row at the bottom of the datagridview.
I need a method to insert a row in the middle of the datagridview, before or after selected row or at the specified position.
I would appreciate your advice.
Re: Iserting new row into Datagridview
The DataRowCollection class, just like any collection type class, has the member "InsertAt" where you can specify an index to insert to. So all you need to do is to use the right method
Code:
tblResults.Rows.InsertAt(theNewDataRow, index)
Re: Iserting new row into Datagridview
Thanks Stanav.
One more question,
how can I know wich row is currently selected?
Re: Iserting new row into Datagridview
DataGridView.CurrentRow gives you the current row of your DGV. From there, you can read the RowIndex property.
Re: Iserting new row into Datagridview