Adding new row to table in DataGridView

  • Thread starter Thread starter bob
  • Start date Start date
B

bob

After adding a new row (programmatically) to a table/view that is being
displayed in the DataGridView control, the new row appears in the
DataGridView grid. Now, how do I select that new row?

If the DataGridView is sorted by one of the columns/fields, the new row
could show up anywhere (based on the sort criteria).

Thanks.
 
Hi Bob,

maybe this helps:
void Grid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
_grid.FirstDisplayedCell =
_grid.Rows[e.RowIndex].Cells[0];
}
 
Thanks for the idea. (What do you know -- there's a "RowsAdded" event
in the thing!). But no, it doesn't help, because "e.rowindex" returns 0
-- I guess the new row gets put first on the grid. But then, if the
grid is sorted (which it always is, in my app), the new row immediately
gets put somewhere else, so the "0" points to the new first row, which
is NOT the one just added. Good idea, though. It makes me want to try
harder to look through all the possible events when I have this kind of
problem. That's something I still need to do with this problem!


Hi Bob,

maybe this helps:
void Grid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
_grid.FirstDisplayedCell =
_grid.Rows[e.RowIndex].Cells[0];
}

bob@datasync.com said:
After adding a new row (programmatically) to a table/view that is being
displayed in the DataGridView control, the new row appears in the
DataGridView grid. Now, how do I select that new row?

If the DataGridView is sorted by one of the columns/fields, the new row
could show up anywhere (based on the sort criteria).

Thanks.
 
Back
Top