简体   繁体   中英

How to add new row to datagridview on the cell click event of the same datagridview?

How to add new row to datagridview on the cell click event of the same datagridview with same content of the previous row.

First, create a mousedown event for the datagridview to get the row number clicked

private void userGrid_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
    rowClicked = e.RowIndex;
}

Then, create a click event that adds the row with the values from the previous row. Continue adding parameters for each column you want to add.

string column1 = queueGridView.Rows[rowClicked - 1].Cells[0].Value.ToString();
string column2 = queueGridView.Rows[rowClicked - 1].Cells[1].Value.ToString();

queueGridView.Rows.Insert(rowClicked, column1, column2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM