Home All Groups Group Topic Archive Search About

Adding new row to table in DataGridView

Author
27 Jun 2006 1:15 PM
bob@datasync.com
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.

Author
2 Jul 2006 5:37 AM
wansch
Hi Bob,

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

Show quoteHide quote
"b**@datasync.com" wrote:

> 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.
>
>
Author
3 Jul 2006 1:41 PM
bob@datasync.com
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!



wansch wrote:
Show quoteHide quote
> Hi Bob,
>
> maybe this helps:
>         void Grid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
>         {
>                        _grid.FirstDisplayedCell =
> _grid.Rows[e.RowIndex].Cells[0];
>         }
>
> "b**@datasync.com" wrote:
>
> > 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.
> >
> >