我希望在鼠标悬停在特定单元格上时更改datagridview中单元格的背景颜色。
尝试过的代码:
private void dataGridView_whateventwillcomehere(object sender, DataGridViewCellEventArgs e)
{
}
答案 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;
}