none
Programmically adding new Row to bottom of DataGridView RRS feed

  • Question

  • I have a unbound datagridview for which i want to add a new row at the bottom when a user selects a value in the 2nd column of a 9 column DGV. The issue is that i have a default value (0.00) programmically entered into the last row once this 2nd column value is entered. When i  call DGV.rows.add() it places the new row at teh top, but when the user enters or changes the last coulmn value then a new row is added at the bottom. I want my programmically added row to be at the bottom and have not found a way of doing this.

    PS. What is the logic behind this different behavior on adding rows?
    Thursday, April 9, 2009 10:08 PM

Answers

  • I found the answer:

    after entering a value into a cell by code for which i want a new row added to the Datagridview i call this method: 

    Me.dgvEmployee.NotifyCurrentCellDirty(True)

    • Marked as answer by Joseph S_ Friday, April 10, 2009 9:03 PM
    Friday, April 10, 2009 9:03 PM

All replies

  • You might try something like this

    DataGridView1.Rows.Insert(DataGridView1.Rows.Count - 1,

    New DataGridViewRow)

    or if allow adding is false then

    DataGridView1.Rows.Insert(DataGridView1.Rows.Count ,

    New DataGridViewRow)


    Coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Thursday, April 9, 2009 11:27 PM
  • I have tried the last one datagridview.rows.insert(datagridview.rowcount, new datagridviewrow) but i get the following error

    "No row can be inserted after the uncommitted new row."

    I have tried several different things to get the DGV to commit everything either user entered or entered by code but i keep coming back to this error.
    Friday, April 10, 2009 4:35 PM
  • I found the answer:

    after entering a value into a cell by code for which i want a new row added to the Datagridview i call this method: 

    Me.dgvEmployee.NotifyCurrentCellDirty(True)

    • Marked as answer by Joseph S_ Friday, April 10, 2009 9:03 PM
    Friday, April 10, 2009 9:03 PM
  • Can I use

    Form5.dgv1.Rows.Add() 
    
    Form5.dgv1.Rows(count - 1).Cells(j).Value() = whatever 

    to add data into the last row?


    I'm using the following code to add data at the top:

     Form5.dgv1.Rows.Insert(0, columna, porchip, varpob)
    Sunday, April 24, 2011 9:36 AM
  • Thanks a lot , it is very useful for us
    Wednesday, August 21, 2019 2:12 PM