如何将一个单元格值复制到其他单元格?

时间:2017-11-07 05:09:23

标签: c# winforms datagridview

我想将内容从一个单元格复制到同一列中的其他单元格。所以我想将该方的名称复制到其他单元格中,最后返回颜色为绿色,如明智的

enter image description here

if (dataGridView1.Rows[j].DefaultCellStyle.BackColor == System.Drawing.Color.Yellow)
{
    int nextRowIndex = j + 1; // the code works up to one cell.

    var value = dataGridView1.Rows[j].Cells[2].Value.ToString();
    dataGridView1.Rows[nextRowIndex].Cells[2].Value = value;
    nextRowIndex++;
}

1 个答案:

答案 0 :(得分:0)

 if (dataGridView1.Rows[j].DefaultCellStyle.BackColor ==System.Drawing.Color.Yellow)
 {
      int nextRowIndex = j + 1; // the code works up to one cell.  
      while (dataGridView1.Rows[nextRowIndex].DefaultCellStyle.BackColor == System.Drawing.Color.Green)
      {
          dataGridView1.Rows[nextRowIndex++].Cells[2].Value = dataGridView1.Rows[j].Cells[2].Value;
      }
}