Ticket T373755
Visible to All Users

How to popup the menu when right click on EMPTY area on a grid

created 9 years ago

[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)

Answers approved by DevExpress Support

created 9 years ago

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.

    Comments (3)
    VD VD
    Victor Doshchenko 4 years ago

      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 }

      Clipboard-File-1.png

      VD VD
      Victor Doshchenko 4 years ago

        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]); } }
        DevExpress Support Team 4 years ago

          Hello,

          Thank you for informing us that the issue has been resolved. Feel free to contact us in case of any questions.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.