Ticket Q465828
Visible to All Users

WinExplorerView - How to keep selection when invoking the context menu

created 11 years ago (modified 11 years ago)

Hello,
We have implemented the new WinExplorer view in our application to simulate the look and feel of Windows Explorer. Unfortunately there is an issue that we have not managed to solve:
Performing an action on a multiple file selection (for instance printing) using the contextual menu. It seems that even though multiple selection works as expected (similar to Windows Explorer), when right-clicking an item the rest of the files besides the one clicked get deselected.
The same behaviour can be seen in the DemoCenter 13.2 -> WinExplorer View (File Manager).
Is there a solution or a work-around to keep all the files selected, even after the context menu is opened?
Thank you in advance!

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello,
From what I gather, you show the context menu when right-clicking an item. In the current implementation of the WinExplorerView, every click is considered for a selection action. So, you need to handle the WinExplorerView.MouseDown event, show the context menu and suppress further processing of the mouse message by enabling the DXMouseEventArgs.Handled option:

C#
void WinExplorerView_MouseDown(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Right) { DevExpress.XtraGrid.Views.WinExplorer.ViewInfo.WinExplorerViewHitInfo hi = WinExplorerView.CalcHitInfo(e.Location); if (hi.InItem) { popupMenu1.ShowPopup(gridControl1.PointToScreen(e.Location)); DXMouseEventArgs.GetMouseArgs(e).Handled = true; }}}

I have attached a simple project that is based on our demo. Change the "directory" variable in your folder.
I understand that our view doesn't behave as a Windows Explorer. I will discuss this issue with our R&D team. Please refer to the WinExplorerView - Selection is not kept when the context menu is shown by pressing RMB thread for further correspondence. We will update that ticket as soon as we make progress.
Feel free to contact us if you need any further assistance.

    Show previous comments (1)
    Andrew Ser (DevExpress Support) 11 years ago

      Hi,
      I see that the context menu is shown on releasing the mouse button in Windows Explorer. I suggest you move the code to the MouseUp event. This will solve the first issue.
      However, the second one is unclear to me. When I click an item with RMB, a context menu is shown but if this click is performed on an unselected item, this item is not selected. Windows Explorer behaves in a similar way.
      If you want to select an item on a right click, check the WinExplorerViewHitInfo.ItemInfo.IsSelected option in the MouseUp event:

      C#
      ... if (hi.InItem) { if (!hi.ItemInfo.IsSelected) WinExplorerView.SelectRow(hi.RowHandle); popupMenu1.ShowPopup(gridControl1.PointToScreen(e.Location)); ...

      Please test the attachment and let us know your result.

        Thank you very much for looking in to my problem.

        Andrew Ser (DevExpress Support) 10 years ago

          Hi,
          I'm happy to hear that the suggested approach is useful for you.

          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.