[DevExpress Support Team: CLONED FROM A1386: How to show a context menu for grid rows]
Please show me how to popup the menu when right click on EMPTY area on a grid. (e.HitInfo haven't property for Empty erea)
How to popup the menu when right click on EMPTY area on a grid
Answers approved by DevExpress Support
Hi Thang,
To know if the GridView's empty area was clicked, check if the GridHitInfo's HitTest property equals GridHitTest.EmptyRow.
Let me know if you have additional questions.
How to add items to Menu if PopupMenuShowingEventArgs.Menu is null?
I try to call menu on empty area of Grid for add new row, but now it is impossible (System.NullReferenceException returned):
C#private void lockView_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
{
GridView view = sender as GridView;
view.FocusedRowHandle = e.HitInfo.RowHandle;
foreach (DXMenuItem item in menuItems)
e.Menu.Items.Add(item); // <= System.NullReferenceException
}
Finally, I solved my problem by this way:
C#private void lockView_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
{
GridView view = sender as GridView;
if (e.Menu == null && e.MenuType == GridMenuType.User && e.HitInfo.HitTest == GridHitTest.EmptyRow)
{
e.Menu = new GridViewMenu(view);
}
e.Menu.Items.Add(menuItems[0]);
if (e.HitInfo.InRow)
{
view.FocusedRowHandle = e.HitInfo.RowHandle;
e.Menu.Items.Add(menuItems[1]);
}
}
Hello,
Thank you for informing us that the issue has been resolved. Feel free to contact us in case of any questions.