ContectMenu, Datagrid & HitTestInfo

  • Thread starter Thread starter MDB
  • Start date Start date
M

MDB

Hello All, I use the below code to get the cell a user clicked in order for
the context menu to pop up and for some reason, I can click on or around the
exact same area and always get different results. Is there something that I
am missing or something I am doing wrong to get the correct cell
(row,column)? One thing I have noticed is that the first time the
contextmenu is displayed that point is always -8,-58 no mater where I click.



private void contextMenu1_Popup(object sender, EventArgs e)

{
Point pt = dgStdAreas.PointToClient( Control.MousePosition );

int x = pt.X;
int y = pt.Y;


DataGrid.HitTestInfo hti = dgStdAreas.HitTest(pt.X,pt.Y);

}
 
It was reported many times on this group that Control.MousePosition
does not work relialby. Since you use DataGrid you are lucky - it has
MouseDown event, which passes as a parameter exact position
of a point where it was tapped.
 
Back
Top