Hi, I am having trouble controlling my cursor behaviour on a forms app. I refer to this pic of part of a DataGridView. My aim - for the cursor to change to a hand when it is over the trash or edit pics.
They work so long as I do not roll over one of the hyperlinks in the grid. As soon as I roll over a hyperlink, the cursor remains an arrow, even when I roll over the two pics.
Any ideas?
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Dave131 reputationPosted Nov 14, 2009, 2:12 PM EST
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.
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 14, 2009, 5:17 AM EST
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.
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 13, 2009, 9:52 PM EST
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;
}
}
Dave131 reputationPosted Nov 14, 2009, 2:12 PM EST
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!
Dave131 reputationPosted Nov 14, 2009, 2:17 PM EST
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;
}
}
}