【问题标题】:selected row colour and selected cell colour选定的行颜色和选定的单元格颜色
【发布时间】:2021-01-18 17:51:30
【问题描述】:

我有一个 Datagridview,我希望当任何行的任何单元格获得焦点时,它的颜色和单元格所在的整行的颜色应该改变,并且当焦点转到另一行时它应该恢复正常.我是编程新手。

【问题讨论】:

    标签: c# winforms datagridview


    【解决方案1】:

    尝试使用 CellContentClick 事件来捕获单元格点击以及单元格控件点击

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
    dataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.Purple;
    dataGridView1.CurrentRow.DefaultCellStyle.ForeColor = Color.WhiteSmoke;
    }
    

    编辑: 没有事件是可能的

    dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Purple;
    dataGridView1.DefaultCellStyle.SelectionForeColor = Color.WhieSmoke;
    

    【讨论】:

      猜你喜欢
      • 2018-10-24
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 2017-06-25
      • 1970-01-01
      • 1970-01-01
      • 2011-01-01
      相关资源
      最近更新 更多