I got a contextmenu in my grid that appears when i right click a cell. The problem i've been having is that when i rightclick a cell while being in editmode the default copy/paste contextmenu appears.
Now i've been able to fire the MouseUp event (and tried MouseDown aswell) using this example:http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=3036
However when i rightclick while being in editmode now i first get the default contextmenu and after i close that (with Esc or clicking somewhere else for example) my contextmenu appears. I just want to disable the default context menu and get my contextmenu to apear right away.
I've been looking around for abit and tried to implement the following code in my form (that contains the UltraGrid):
protected override void WndProc(ref System.Windows.Forms.Message m) { //Suppress the message to display the context menu const int WM_CONTEXTMENU = 0x7b; if (m.Msg != WM_CONTEXTMENU) this.WndProc(ref m); }
Apperantly overriding the WndProc function lets you suppress default windows behaviour but i've not been able to get it to work. I get a stackoverflow on the If statement while loading the form.
What i mostly find weird is that i saw a similair topic on this forum:http://forums.infragistics.com/forums/t/5035.aspx
However he does not have the default copy/paste contextmenu problem.
Thanks in advance.
Hi Chris,
I'm not following you. You say the "click cell" event fires before MouseDown? That doesn't sound right. MouseDown would have to fire first, I think.
chris_o_10 said:The mouse event is then triggered but the menu won't be displayed as I have have not clicked the right mouse button.
I'm not sure what you mean by this, either. If you are not clicking the mouse button, then why is click or MouseDown firing?
You may be better off using MouseDown or MouseMove to assign your context menu to the grid using the UltraToolbars SetContextMenu method, rather than ShowPopup. That way the context menu becomes associated with the grid and the grid will handle showing it whenever the system would normally show a context menu.
EDIT: By the way, showing a context menu in MouseDown is not a good idea and can easily cause problems in your application. If you try this out with any Windows application, you will find that it's a standard to show a context menu in the MouseUp, never MouseDown. Using MouseDown means that the control you clicked gets a MouseDown and then MouseUp message goes to the menu and not the control, which can leave the control confused because it got a MouseDown with no MouseUp.
I have now manged to fix this
thanks
Chris
Hi,
sorry for resurrecting this thread however after doing a search on the forum it was the closest match..
I'm too having difficulties applying my own pop up menu when a cell is in edit mode. The menu (only paste option atm) works fine when I right click anywhere on the grid.
This is my current code in the Mouse down event;
private void gvUserData_MouseDown(object sender, MouseEventArgs e)
{
UIElement mousedownUIElement = null;
if (e.Button == MouseButtons.Right) {
mousedownUIElement = gvUserData.DisplayLayout.UIElement.ElementFromPoint(new Point (e.X, e.Y));
}
if (mousedownUIElement != null)
UltraGridCell mCell;
mCell = mousedownUIElement.GetContext(typeof(UltraGridCell)) as UltraGridCell;
if (mCell != null)
gvUserData.ActiveCell = mCell;
toolbarsManager.ShowPopup("UserGridPopup");
I have a method that handles the click cell event and enters edit mode. The mouse event is then triggered but the menu won't be displayed as I have have not clicked the right mouse button. Is there a way that this method could be called again once in edit mode??
Thanks
I have made it so that it doesn't really matter that much that it get fired twice so gonna let it rest for now as i have some other things to do. I might make a demo project in the future. Thanks anyway for all the help.
Not sure what to tell you there. If you can duplicate this behavior in a small sample project, I will be happy to take a look. It's possible that this is a bug in the grid, but I am not aware of any such issues.