代码之家  ›  专栏  ›  技术社区  ›  Jack.D

Datagridview特定行更改背景颜色

  •  0
  • Jack.D  · 技术社区  · 8 年前

    我试图突出显示datagridview中列为“E”的选定行变为红色,但如果第一行的状态为“E”,则下一行也变为红色(尽管状态为“i”)。

    enter image description here

    SelectionChanged事件

    int sel = datagridview.SelectedCells[0].RowIndex;
        DataGridViewRow Row = dataGridView.Rows[sel];
        if(!File.Exists(path))
        {
           Row.Cells[4].Value = "E"
           for(int i=0;i<5;i++)
           {
              Row.Cells[i].Style.BackColor = Color.Red;
           }
        }
    

    enter image description here

    1 回复  |  直到 8 年前
        1
  •  1
  •   Jack.D    8 年前

    只要使用dataGridView_CurrentCellChanged事件就可以解决这个问题。