Adding new row to table in DataGridView

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.
 
G

Guest

Hi Bob,

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

bob

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];
}

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top