110,534
社区成员
发帖
与我相关
我的任务
分享
//Call SwitchDataGridViewRow Method
private void button1_Click(object sender, EventArgs e)
{
SwitchDataGridViewRow(0, 1);
}
//Switch DataGridViewRow
private void SwitchDataGridViewRow(int nRow1, int nRow2)
{
DataGridViewRow tmp = new DataGridViewRow();
tmp.CreateCells(dgv_main);
for (int i = 0; i < dgv_main.Columns.Count; i++)
{
tmp.Cells[i].Value = dgv_main.Rows[nRow1].Cells[i].Value;
dgv_main.Rows[nRow1].Cells[i].Value = dgv_main.Rows[nRow2].Cells[i].Value;
dgv_main.Rows[nRow2].Cells[i].Value = tmp.Cells[i].Value;
}
}