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.
I have handled the following events:
private void dgvBookLibrary_CellMouseEnter(object sender, DataGridViewCellEventArgs e) { switch (dgvBookLibrary.Columns[e.ColumnIndex].Name) { case "ColumnDelete": case "ColumnAmend": this.Cursor = Cursors.Hand; break; default: break; } }
private void dgvBookLibrary_CellMouseLeave(object sender, DataGridViewCellEventArgs e) { switch (dgvBookLibrary.Columns[e.ColumnIndex].Name) { case "ColumnDelete": case "ColumnAmend": this.Cursor = Cursors.Arrow; break; default: break; } }
|
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?
Nilanka DharmadasaPosted Nov 14, 2009, 10:17 AM
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.
DavePosted Nov 14, 2009, 7:17 PM
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;
}
}
}
DavePosted Nov 14, 2009, 7:12 PM
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!
Kirtan PatelPosted Nov 14, 2009, 2:52 AM
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;
}
}