In the gridview I am trying to handle the right-click on a cell to instantly show the context menu rather than having to first left click in the cell and then right click to get the context menu.
I have followed suggested in the Support center, however, my code has no effect - the cell does still not have a focused border and the context menu is not displayed. I have stepped through my code and found the focused row and column are set, the active editor is set appropriately based on the data type of the cell, and the appropriate context menu is set (some have custom context menus).
Here is the code I am using:
private void gridView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
GridView view = sender as GridView;
GridHitInfo hitInfo = view.CalcHitInfo(e.Location);
if (hitInfo.InRow)
{
view.FocusedColumn = hitInfo.Column;
view.FocusedRowHandle = hitInfo.RowHandle;
view.ShowEditor();
view.ActiveEditor.SendMouse(e.Location, MouseButtons.Right);
}
}
}
Thanks, any help will be greatly appreciated.
Terri
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 Terri,
If I understand your task correctly, you want to show the editor's context menu rather than a GridView's menu. If so, you should recalculate the mouse position inside the editor. You should also set the DXMouseEventArgs.Handled property to true to suppress the default action, performed on mouse down. Please try to use the following code:
private void gridView1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ((DXMouseEventArgs)e).Handled = true; GridView view = sender as GridView; GridHitInfo hitInfo = view.CalcHitInfo(e.Location); if (hitInfo.InRow) { view.FocusedColumn = hitInfo.Column; view.FocusedRowHandle = hitInfo.RowHandle; view.ShowEditor(); view.ActiveEditor.SendMouse(view.ActiveEditor.PointToClient(Cursor.Position), MouseButtons.Right); } } }
Please let me know whether the result meets your requirements.
Thanks,
Anatol
Not exactly what I am trying to accomplish. What I want to do when I right-click on a cell is to:
Basically handle the left-click and the right-click when right-clicking on a cell, rather than having to first left-click and then right-click.
Based on the type of my data, I am dynamically creating the editor when I populate the control. These can be RepositoryItemTextEdit, RepositoryItemImageEdit, RepositoryItemPictureEdit, RepositoryItemDateEdit or RepositoryItemComboBox.
With the addition of your suggestion to set mouse handled event to true, the cell is focused, but the dropdowns for editors that have them (date, image, picture, combobox) are not displayed - and the context menus are displayed only for the types that I have defined a custom menu (image and picture).
Without your suggestion as I originally coded it, the cell does not appear to have input focus, the dropdowns for editors that have them are not displayed and no context menus (custom or default) are displayed.
Hello Terri,
I'm afraid that your scenario is not quite clear to me. Please provide a sample project that demonstrates what happens in your application when you first left-click and then right-click on a cell, and describe what action should be performed in this project when only right-clicking on the cell.
Thanks,
Anatol
What I'm trying to accomplish is to instantly show the popup menu when right clicking on a cell, rather than having to left click the cell (to get focus) and then right click to get the menu. (Same as issue Q257416 and DQ50174). But the solution there doesn't completely work for me.
I had problems attaching multiple images, so I've attached a document with the images to help explain what I'm trying to accomplish (sample of both text and photo editors). The "right click in new cell" examples are using the gridview1_MouseDown event handler as you proposed (which is better than what I was using as proposed in Q257416 but still not exactly what I want to accomplish).
I hope this helps clarify my question. If not I'll work on a sample project - my current project is much too large.
Terri
Hello Terri,
I've created a sample project. It appears that the first issue, demonstrated in the attached document, doesn't occur in it. The second issue is resolved by sending additional mouse events to the editor. Please let me know whether the result meets your requirements.
Thanks,
Anatol
Yes - that does exactly what I want. Thanks for your help!
Terri
You are always welcome.
Thanks,
Anatol