简体   繁体   English

如何在同一个datagridview的单元格单击事件上向datagridview添加新行?

[英]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.如何在具有与上一行相同内容的同一 datagridview 的单元格单击事件上向 datagridview 添加新行。

First, create a mousedown event for the datagridview to get the row number clicked首先,为datagridview创建一个mousedown事件以获取点击的行号

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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