datagridview单元格鼠标悬停backcolor更改

时间:2015-07-10 09:41:48

标签: c# .net c#-4.0 datagridview mouseover

我希望在鼠标悬停在特定单元格上时更改datagridview中单元格的背景颜色。

尝试过的代码:

private void dataGridView_whateventwillcomehere(object sender, DataGridViewCellEventArgs e)
        {

        }

1 个答案:

答案 0 :(得分:8)

CellMouseMove活动

上试试
private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
{
    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Blue;
}

您需要CellMouseLeave事件才能恢复颜色

private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.White;
}