Hello,
I am trying to display context menu only when a user clicks on any row in ultragrid. I am using the code below.
UIElement aUIElement =
this.ultraGridSearchList.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y));
UltraGridRow aRow = null;
Infragistics.Win.UltraWinGrid.
ColumnHeader mouseupColumnHead = null;
Point p = PointToScreen(MousePosition);
if (aUIElement != null)
{
///Declare and retrieve a reference to the row
aRow = (
UltraGridRow)aUIElement.GetContext(typeof(UltraGridRow));
mouseupColumnHead = (Infragistics.Win.UltraWinGrid.
ColumnHeader)aUIElement.GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader), true);
}
if (e.Button == System.Windows.Forms.MouseButtons.Right && aRow != null && mouseupColumnHead == null)
contextMenuStripPreviewPane.Show(PointToScreen(p));
return;
But my context menu is not appearing at exact mouse position when clicked. Is there any seperate why to try out.
I have tried PointToClient as well.
Hi Mike,
Thanks , It worked.
Hi,
I think you are correct to use PointToScreen here, since the ContextMenu expect screen coords. But I think the problem is that you are using PointToScreen of the Form. PointToScreen is a method on control and it needs to know what control it's dealing with in order to properly convert the coordinates.
Try using grid.PointToScreen.
Hello rooma,
Could you try to use just 'MousePosition' for the p variable and not PointToScreen(MousePosition). Also pass PointToClient(p) to the Show() method and let me know of the result satisfies your needs.