Adding new row to table in DataGridView

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bob@datasync.com

    #1

    Adding new row to table in DataGridView

    After adding a new row (programmatical ly) 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.

  • wansch

    #2
    RE: Adding new row to table in DataGridView

    Hi Bob,

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

    "bob@datasync.c om" wrote:
    After adding a new row (programmatical ly) 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.
    >
    >

    Comment

    • bob@datasync.com

      #3
      Re: Adding new row to table in DataGridView

      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:
      Hi Bob,
      >
      maybe this helps:
      void Grid_RowsAdded( object sender, DataGridViewRow sAddedEventArgs e)
      {
      _grid.FirstDisp layedCell =
      _grid.Rows[e.RowIndex].Cells[0];
      }
      >
      "bob@datasync.c om" wrote:
      >
      After adding a new row (programmatical ly) 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.

      Comment

      Working...