When using the winforms grid, if I select a row in a grid, then right-click on empty space (below the rows, where additional rows would otherwise be), the ContextMenu is opened however the rows stay selected, so the context menu will operate on the selected rows (when it uses GetSelectedRows() to find out what was selected).
Doing the same thing in Windows Explorer behaves differently: selecting a file & right-clicking in empty space causes the selected file to be de-selected, and the context menu which shows is related to the empty space (not the file which is now de-selected).
The second of these is the behavior I need, so that after a right-click fires, what remains selected is relative to where the right-click occurred.
Is there a setting in the grid, which causes the selected row to be de-selected if empty space is clicked (as it is in windows explorer)?
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.
Hello Mark,
The XtraGrid doesn't have a predefined menu for the rows area. I assume that you've implemented your own menu that you invoke from an ShowGridMenu event handler. You can create an additional context menu for the empty area below the last row. To invoke it, check the e.HitInfo.HitTest parameter against the DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitTest.EmptyRow value.
Thanks,
Nick
--------------------
Check if Search Engine is able to answer questions faster than I do!
I'm not sure my question's been understood clearly. I'm attaching a ContextMenuStrip to the grid control, so it pops open after a right-mouse click. (I'm reusing context menus which are also used on other controls, so I can not use a DX proprietary approach).
When the ContextMenuStrip pops open, I filter the menu based on which row(s), or no rows, were selected when the context menu popped. It works fine for right-clicking when one or more rows are selected in the grid. Where the problem is, is when I right-click on the empty area, a row from the grid stays selected, when it should de-select (as it does in windows explorer, as an example).
The attached screen capture shows a Dx grid, and in the bottom right corner, I did a right-mouse to trigger the context menu. Notice that the grid row remains selected, even though I clicked on the empty space below the rows. My issue is, how do I get the row to be de-selected, as a result of a right-click on the empty area (ie. moving the context to the empty area should de-select the rows)?
Hello Mark,
You should not assign a ContextMenuStrip directly to the grid control. Instead, handle the ShowGridMenu event and open the menu for those grid elements where you need it. Please review the following article. It should help.
How to show a context menu for grid rows
Thanks,
Nick
--------------------
Check if Search Engine is able to answer questions faster than I do!
Thanks Nick, that helps, but it still has the same behavior which I am trying to avoid.
When I run the sample project and right-click in the empty space below the rows, the currently selected row in the grid retains focus.
I can check for hitInfo.HitTest == EmptyRow, however how to I remove focus from a row? That is, make the grid such that no rows are selected/focused?
Hi Mark,
The XtraGrid always has a focused row and it cannot be deselected. You can try to visually dim down the focused row as shown in the Is it possible to set up the grid to have no focused row? article. However, in my opinion, an easier solution would be displaying a different context menu for the empty area. This menu should not contain row related commands which are available from your context menu for rows.
Thanks,
Nick
--------------------
Check if Search Engine is able to answer questions faster than I do!
Thanks