datagridview单元格鼠标悬停背景色更改
问题描述:
我想在鼠标悬停在特定单元格上时更改datagridview中单元格的背景色.
i want to change the backcolor of cell in datagridview while mouse hover on particular cell.
尝试的代码:
private void dataGridView_whateventwillcomehere(object sender, DataGridViewCellEventArgs e)
{
}
答
在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;
}