Results 1 to 5 of 5

Thread: [RESOLVED] Iserting new row into Datagridview

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    204

    Resolved [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.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    204

    Re: Iserting new row into Datagridview

    Thanks Stanav.
    One more question,
    how can I know wich row is currently selected?

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Iserting new row into Datagridview

    DataGridView.CurrentRow gives you the current row of your DGV. From there, you can read the RowIndex property.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    204

    Re: Iserting new row into Datagridview

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width