datagridview cell mouse hover backcolor change

冷暖自知 提交于 2019-12-23 03:41:08

问题


i want to change the backcolor of cell in datagridview while mouse hover on particular cell.

Tried code:

private void dataGridView_whateventwillcomehere(object sender, DataGridViewCellEventArgs e)
        {

        }

回答1:


Try this on CellMouseMove Event

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

You need CellMouseLeave Event to restore color

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


来源:https://stackoverflow.com/questions/31337566/datagridview-cell-mouse-hover-backcolor-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!