How do I change the datagridview selected row background color?

后端 未结 6 656
无人共我
无人共我 2020-12-03 13:06

How do I change the datagridview selected row background color in C# windows applications?

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 13:57

    Taking advantage of DataGridViewCell's events CellEnter and CellLeave you might try something like this:

    private void foobarDataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)
    {
      DataGridViewCellStyle fooCellStyle = new DataGridViewCellStyle();
      fooCellStyle.BackColor = System.Drawing.Color.LightYellow;
      this.VariableFinderDataGridView.CurrentCell.Style.ApplyStyle(fooCellStyle);
    }
    
    private void foobarFinderDataGridView_CellLeave(object sender, DataGridViewCellEventArgs e)
    {
      DataGridViewCellStyle barCellStyle = new DataGridViewCellStyle();
      barCellStyle.BackColor = System.Drawing.Color.White;
      this.VariableFinderDataGridView.CurrentCell.Style.ApplyStyle(barCellStyle);
    }
    

提交回复
热议问题