We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Removing context menus from underlying cells

I''m running the code below (gets invoked in the Form_Load) to try to get rid of the standard context menus that appear when a textbox or maskedit control is editing. It works for the textboxes but not the MaskEdit controls - do I need to invoke it somewhere else? GridTextBoxCellRenderer tb = (GridTextBoxCellRenderer)this.CellRenderers["TextBox"]; tb.TextBox.ContextMenu = new ContextMenu(); GridMaskEditCellRenderer me = (GridMaskEditCellRenderer)this.CellRenderers["MaskEdit"]; me.Control.ContextMenu = new ContextMenu();

8 Replies

AD Administrator Syncfusion Team June 15, 2004 03:13 PM UTC

Try handling CurrentCellControlGotFocus, and setting a empty ContextMenu there.
private void gridControl1_CurrentCellControlGotFocus(object sender, ControlEventArgs e)
{
	if(e.Control.ContextMenu == null )
		e.Control.ContextMenu = new ContextMenu();
}


LS Lori S. Pearsall June 15, 2004 07:49 PM UTC

That worked. I''ve gone a slightly different way - I''m hooking the CellRenderer controls in my parent form like this : private void gridParty_CurrentCellControlGotFocus(object sender, System.Windows.Forms.ControlEventArgs e) { if (e.Control is GridMaskedEditBox) { if (e.Control.ContextMenu != null) e.Control.ContextMenu = new ContextMenu(); if (this.popupMenusManager.GetXPContextMenu (e.Control) != this.popupMenuParty) this.popupMenusManager.SetXPContextMenu (e.Control, this.popupMenuParty); } } private void gridParty_CurrentCellControlLostFocus(object sender, System.Windows.Forms.ControlEventArgs e) { if (e.Control is GridMaskedEditBox) { if (this.popupMenusManager.GetXPContextMenu (e.Control) == this.popupMenuParty) this.popupMenusManager.SetXPContextMenu (e.Control, null); e.Control.ContextMenu = null; } } This works exactly as I wanted it to, my XPMenu is invoked from within the MaskEdit cell control. Of course, there''s a catch. Now my Dispose() blows up with the attached stack trace if I enter a MaskEdit cell. I''ve verified in the Dispose that the LostFocus code is being called prior to anything being disposed (did a MoveTo(-1,-1)). I even watched the PopupMenuManager decrement it''s count of menus to verify that reference was removed. stacktrace_9056.zip


AD Administrator Syncfusion Team June 15, 2004 08:13 PM UTC

You get this error when you first click into a MaskEdit cell? That is strange as why would teh MaskEdit be disposing at that time. From your stack trace, it looks like you are using a GridRecordnavigationControl. If so, are you hooking and unhooking these GotFocus and LostFocus events in the PaneCreated and PaneClosing events. http://www.syncfusion.com/Support/article.aspx?id=580


LS Lori S. Pearsall June 15, 2004 09:42 PM UTC

>You get this error when you first click into a MaskEdit cell? That is strange as why would teh MaskEdit be disposing at that time. I get the error if I click in a MaskEdit cell and then close the form (doesn''t have to be the last cell that I''m in). >From your stack trace, it looks like you are using a GridRecordnavigationControl. If so, are you hooking and unhooking these GotFocus and LostFocus events in the PaneCreated and PaneClosing events. http://www.syncfusion.com/Support/article.aspx?id=580 Yes, I am.


AD Administrator Syncfusion Team June 16, 2004 05:54 AM UTC

Instead of trying hook and unhook the menu continuously, how about hooking it only once in GotFocus (and not have any LostFocus code). The idea would be that the control going out of scope would trigger the default clean up code and hopefully this would not caused a Dispose problem. You coul dtry a simple test of this idea by commentting out your LostFocus code, running the program clicking once in the MaaskEdit cell, then clicking some other type of cell and immediately closing the form. If this avoid the dispose problem you could try to re-design you GotFocus code to execute only once for each new pane.


LS Lori S. Pearsall June 16, 2004 11:44 AM UTC

Hi Clay, Actually, that''s what I started with. I added the LostFocus code thinking that the reason I was blowing up in the Dispose was because I needed to unhook the menu. Anyway, I commnted out the LostFocus code and put WriteLine''s in the GotFocus to verify that the SetXPContextMenu was only being executed once. Still receiving the same error. >Instead of trying hook and unhook the menu continuously, how about hooking it only once in GotFocus (and not have any LostFocus code). The idea would be that the control going out of scope would trigger the default clean up code and hopefully this would not caused a Dispose problem. > >You coul dtry a simple test of this idea by commentting out your LostFocus code, running the program clicking once in the MaaskEdit cell, then clicking some other type of cell and immediately closing the form. If this avoid the dispose problem you could try to re-design you GotFocus code to execute only once for each new pane.


LS Lori S. Pearsall June 16, 2004 08:49 PM UTC

Would this be more appropriate as a Direct-Trac incident?


AD Administrator Syncfusion Team June 16, 2004 10:45 PM UTC

We will need a sample to try to resolve this issue. You can provide one here, or through Direct Trac.

Loader.
Live Chat Icon For mobile
Up arrow icon