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!
WinExplorerView - How to keep selection when invoking the context menu
Answers approved by DevExpress Support
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.
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.