Alex,
To explain, I have MainForm that has a ToolBar added in the designer and the
code snippet below:
private ToolBar toolBar; // from designer
private ToolBarButton toolBarButtonX;
private ContextMenu conMenuX;
private bool condition;
public MenuItem miRep1, miRep2, miRep3, miRep4, miRep5;
public MainForm() // (MainForm Constructor)
{
...
...
InitializeComponent();
// Added these controls outside of designer
this.toolBarButtonX = new ToolBarButton();
this.conMenuX = new ContextMenu();
this.toolBar.Buttons.Add(this.toolBarButtonX);
this.toolBarButtonX.Enabled = true;
this.toolBarButtonX.ImageIndex = 5; // from my code
this.toolBarButtonX.Visible = true;
this.condition = false; // default setting
}
private void InitializeComponent()
{
....
this.miRep1 = new MenuItem();
this.miRep2 = new MenuItem();
this.miRep3 = new MenuItem();
this.miRep4 = new MenuItem();
this.miRep5 = new MenuItem();
....
....
this.miRep1.Enabled = ((bool)(resources.GetObject("miRep1.Enabled")));
this.miRep1.Text = resources.GetString("miRep1.Text");
this.miRep1.Click += new System.EventHandler(this.Rep1_OnClick);
this.miRep2.Enabled = ((bool)(resources.GetObject("miRep2.Enabled")));
this.miRep2.Text = resources.GetString("miRep2.Text");
this.miRep2.Click += new System.EventHandler(this.Rep2_OnClick);
this.miRep3.Enabled = ((bool)(resources.GetObject("miRep3.Enabled")));
this.miRep3.Text = resources.GetString("miRep3.Text");
this.miRep3.Click += new System.EventHandler(this.Rep3_OnClick);
this.miRep4.Enabled = ((bool)(resources.GetObject("miRep4.Enabled")));
this.miRep4.Text = resources.GetString("miRep4.Text");
this.miRep4.Click += new System.EventHandler(this.Rep4_OnClick);
this.miRep5.Enabled = ((bool)(resources.GetObject("miRep5.Enabled")));
this.miRep5.Text = resources.GetString("miRep5.Text");
this.miRep5.Click += new System.EventHandler(this.Rep5_OnClick);
....
....
}
private void toolBar_ButtonClick(object obj, ToolBarButtonClickEventArgs e)
// ToolBar event handler
{
if (e.Button.Equals(this.toolBarButtonX))
{
EventArgs eax = new EventArgs();
ConMenuX_PopUp(this, eax);
}
}
private void ConMenuX_PopUp(object obj, EventArgs ea) // ContexMenu
handler
{
Point pt = new Point(60, 160);
this.conMenuX.Show(this, pt);
}
// This method prepares the ContextMenu to display different reports
depending on a condition
// It is called from another method in the program after the condition is
set
private void PrepRepMenu()
{
this.conMenuX.MenuItems.Clear(); // Kill any current menu
item entries
if (this.condition)
{
this.conMenuX.MenuItems.Add(this.miRep1);
this.conMenuX.MenuItems.Add(this.miRep2); <== Fails here
System.ArgumentException
this.conMenuX.MenuItems.Add(this.miRep4);
this.conMenuX.MenuItems.Add(this.miRep5);
}
else // True if other condition
{
this.conMenuX.MenuItems.Add(this.miRep1);
this.conMenuX.MenuItems.Add(this.miRep2); <== Fails here
System.ArgumentException
this.conMenuX.MenuItems.Add(this.miRep3);
}
}
Apparently, Daniel Moth had a similar problem last year and MS suggested
that these was a bug underthese circumstances.
Regards,
Neville Lang
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Alex Feinman [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I wonder of you could get aroound it by setting a short (100 msec)
one-shot
> timer and invoking the menu from the timer event.
> Another thing to try is calling Application.DoEvents before doing things
> with the menu.
> Understand, I'm shooting in the dark here since you haven't provided a
code
> snippet or a repro project
>
> --
> Alex Feinman
> ---
> Visit http://www.opennetcf.org
> "Neville Lang" <neville@MAPS_ONnjlsoftware.com> wrote in message
> news:(E-Mail Removed)...
> > Hi all,
> >
> > The problem I am having is with a ContextMenu that is called from a
> > ToolBarButton, set as a PushButton style. The ContextMenu is raised from
> > the
> > Click event of that button.
> >
> > For some reason, I found that using the DropDownButton style of a
> > ToolBarButton would lockup (freeze) some PPCs, like the Toshiba e335 but
> > not
> > the HP iPAQ 3900 series.
> >
> > To counter this problem, I decided to use a ToolBarButton with the
> > PushButton style and link it separately to a Context menu using the
Click
> > event. I can now report that this design now prevents the Toshiba e335
> > from
> > freezing, so I have at least fixed that problem. It also continues to
work
> > normally on HP iPAQs.
> >
> > However, a new problem has emerged. At runtime, I use a method to load a
> > different set of MenuItems on the ContextMenu depending on some flags. I
> > do
> > this by using the MenuItem.Clear() method. I now find that while I could
> > do
> > this with the ToolBarButton set to the DropDownMenu style, I cannot now
do
> > the same thing with a separate ContextMenu triggering it from a Click
> > event
> > of the ToolBarButton. I get a "System.ArgumentException" error.
> >
> > It seems Daniel Moth also had a similar problem to this in August 2003.
> > Katie from Microsoft indicated that it was a bug in CF.
> >
> > Daniel, did you find a way around this problem of loading different
> > MenuItems at runtime?
> >
> > Microsoft, has this problem been fixed yet, maybe with CF v1.0 SP3 beta?
> > It
> > is still a problem with CF v1.0 SP2.
> >
> > Does anyone else have a workaround for this known bug?
> >
> > I suspect this ContextMenu problem might also have something to do with
> > the
> > freeze on a Toshiba e335 PPC when using the ToolBarButton style set to
> > DropDownMenu but I cannot be sure.
> >
> > Regards,
> > Neville Lang
> >
> >
>
>