i'm trying simulate a hover event in a DataGridView
control to show a Cursor.Hand
when a DataGridViewImageColumn
has hovered
I'm trying this (suscribe to CellMouseEnter
)
dgv_tabla.CellMouseEnter += dgv_tabla_Hover;
And checking if RowIndex
is not -1
private void dgv_tabla_Hover(object sender, DataGridViewCellEventArgs e)
{
//The index of the column where i want to show Cursor.Hand
var index = dgv_tabla.Columns["Remove"].Index;
if (e.ColumnIndex == index && e.RowIndex >= 0)
dgv_tabla.Cursor = Cursors.Hand;
else
dgv_tabla.Cursor = Cursors.Default;
}
The problem, is when i'm hovering "Remove" cell and move the mouse down (to the ''grey area''), then, the Cursor.Hand
dont change to Cursor.Default
Is any way to achieve this?
Thanks!
Another solution would be to use the MouseMove
event and do a HitTest
as suggested by TaW in the comments above. In this case, your code would look something like this:
dgv_tabla.MouseMove += Dgv_tabla_MouseMove;
private void Dgv_tabla_MouseMove(object sender, MouseEventArgs e)
{
int index = dgv_tabla.Columns["Remove"].Index;
DataGridView.HitTestInfo info = dgv_tabla.HitTest(e.X, e.Y);
if (info.ColumnIndex == index && info.RowIndex >= 0)
dgv_tabla.Cursor = Cursors.Hand;
else
dgv_tabla.Cursor = Cursors.Default;
}