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.
Unfortunately, activation email could not send to your email. Please try again.

Removing context menus from underlying cells

Thread ID:

Created:

Updated:

Platform:

Replies:

15256 Jun 15,2004 10:49 AM Jun 16,2004 06:45 PM Windows Forms 8
loading
Tags: GridControl
Lori S. Pearsall
Asked On June 15, 2004 10:49 AM

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();

Administrator [Syncfusion]
Replied On June 15, 2004 11:13 AM

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();
}

Lori S. Pearsall
Replied On June 15, 2004 03:49 PM

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

Administrator [Syncfusion]
Replied On June 15, 2004 04:13 PM

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

Lori S. Pearsall
Replied On June 15, 2004 05:42 PM

>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.

Administrator [Syncfusion]
Replied On June 16, 2004 01:54 AM

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.

Lori S. Pearsall
Replied On June 16, 2004 07:44 AM

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.

Lori S. Pearsall
Replied On June 16, 2004 04:49 PM

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

Administrator [Syncfusion]
Replied On June 16, 2004 06:45 PM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;