1
Hi Dave,
As kritan said, you do not need mouse leave event. But still there should be another change.
Change the cursor property of datagridview without changing the cursor of the form.
private void dgvBookLibrary_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if ((e.ColumnIndex == 3) || (e.ColumnIndex == 4))
{
this.dgvBookLibrary.Cursor = Cursors.Hand;
}
else
{
this.dgvBookLibrary.Cursor = Cursors.Default;
}
}
If you find this answer useful, please do not forget to mark this accepted.
Accepted 0
I take that back, I don't need to handle the CellMouseLeave event. This is my final code (I have a thing for switch statements)
private void dgvBookLibrary_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex > -1)
{
switch (dgvBookLibrary.Columns[e.ColumnIndex].Name)
{
case "ColumnDelete":
case "ColumnLendBook":
case "ColumnReturn":
case "ColumnAmend": dgvBookLibrary.Cursor = Cursors.Hand; break;
default: dgvBookLibrary.Cursor = Cursors.Default; break;
}
}
}
0
Thanks guys.
I found that you do need to handle the CellMouseLeave event, otherwise the cursor remains a hand.
But Niki nailed it by pointing out that I should have been chnaging the DataGridView cursor, rather than the Form cursor. I did not think of that at all.
Works fine now.
Cheers!
0
Friend,
you need to Write code like Below
if my answer helps you then check "Do you like this Answer check box" please :)
private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
//Here i have Assumed that Column Index For Delete is 1 you need to use Your Column Index
if(e.ColumnIndex == 1)
{
this.Cursor = Cursors.Hand;
}
else
{
this.Cursor = Cursors.Default;
}
}