user3747256
user3747256

Reputation: 113

datagridview cell mouse hover backcolor change

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)
        {

        }

Upvotes: 4

Views: 19090

Answers (1)

M. Nasir Javaid
M. Nasir Javaid

Reputation: 5990

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;
}

Upvotes: 13

Related Questions