Hi,

I am having problems using the GWMenuItem object.

Background:
GroupWise Client Version: 7.0.1
Language: C# 2005

I've been asked to write a C3PO that will read an initialisation file
listing GroupWise client menus/menu items that should be deleted (e.g. the
document management stuff).

Simply to begin with I've tried to enumerate all the menus and determine
the type of object (Menu, MenuAction or Separator) but when I try to use
the GWMenuItem object the InvalidCastException gets thrown.

Specifically when I try to set a GWMenuItem object in either a foreach
loop through a MenuItems collection or during a for (int i = 1; i <=
SubMenuItems.Count; i++) loop I get an exception thrown.

e.g.

C3POTypeLibrary.GWMenuItem MnuItm;
MnuItm = (C3POTypeLibrary.GWMenuItem)SubMenuItems.Item(i);

throws an InvalidCastException.

The full procedure code is shown at the end of this post.

Can anyone see why this is happening?

Many thanks in advance,

Andy

CODE:

private void EnumerateMenuItems(C3POTypeLibrary.GWMenu TopMenu)
{
try
{
//Get the menu items collection for the Top Level Menu object.
C3POTypeLibrary.GWMenuItems TopMenuItems;
TopMenuItems = (C3POTypeLibrary.GWMenuItems)TopMenu.MenuItems;

foreach (C3POTypeLibrary.GWMenu TopLevelMenu in TopMenuItems)
{
// This loop goes through File, Edit View ... Help

if (TopLevelMenu.ObjType ==
C3POTypeLibrary.GWOBJTYPE.eGW_GWMENU)
{
// Create a menu items collection for each top level menu.
C3POTypeLibrary.GWMenuItems SubMenuItems;
SubMenuItems =
(C3POTypeLibrary.GWMenuItems)TopLevelMenu.MenuItem s;

//Loop through the menu items below File, Edit ...

//for (int i = 1; i <= SubMenuItems.Count; i++)
for (int i = 1; i <= 3; i++) // Whilst debugging limit the
number of iterations.
{
try
{
C3POTypeLibrary.GWMenuItem MnuItm;
//The following line raises an
System.InvalidCastException exception.
MnuItm =
(C3POTypeLibrary.GWMenuItem)SubMenuItems.Item(i);
}
catch (Exception e)
{
MessageBox.Show("Exception caught: " +
e.ToString(), "Sub Menu: " + TopLevelMenu.Caption, MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
}
}
catch (Exception e)
{
MessageBox.Show("Failed to enumerate through all menus." + "nn" +
e.Message,
"DEBUG: Menu Enumeration", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}