• Advertisement
Sign in to follow this  

No Submenus for you, for one year!

This topic is 4269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay so what I'm doing is creating a navigation aid for use with a map. Basically as the user moves around the map, he/she can make "memory points" so that he/she can instantly navigate there by simply right clicking in the map area and then picking from a list of submenus (previously saved nav points) in order to quickly navigate on the map. The problem I'm having is that if I add more than 2 submenus to a navigation menu item then the "click" event handler doesn't fire, If I have <= 2 then the event handler fires... heres some code.... For this code block I popup a text field where the user can name the navigation point. Once he/she presses "enter" the data updates the appropriate data structures...
if (e.KeyCode == System.Windows.Forms.Keys.Enter) {
	
    NameField.Hide();

    // menu is no longer visible
    IO.BoolParameter = false;
    ProgramMGR.SetValue(CProgramMGR.Parameters.IsNavigationMenuVisible, IO);

    if (NameField.Text == null) NameField.Text = " ";

    // now add the menu item
    Map.GetValue(CMap.Parameters.MapStartOffset, ref IO);
    NavigationPoints tempNavPt = new NavigationPoints();
    tempNavPt.name = NameField.Text;
    tempNavPt.Coordinates.X = IO.PointParameter.X;
    tempNavPt.Coordinates.Y = IO.PointParameter.Y;
    NavPoints.Add(tempNavPt);
    MenuItem tempMenu1 = new MenuItem();
    MenuItem tempMenu2 = new MenuItem();

    tempMenu1.MenuItems.Add(tempNavPt.name, new EventHandler   
       (NavPtClick_Deletion));
    tempMenu2.MenuItems.Add(tempNavPt.name, new EventHandle
       (NavPtClick_Navigation));

    NavigationMenu.MenuItems[2].MergeType = MenuMerge.Replace;
    NavigationMenu.MenuItems[2].MergeMenu(tempMenu2);
    NavigationMenu.MenuItems[1].MergeMenu(tempMenu1);
    NavigationMenu.MenuItems[1].Text = "Navigation";
				
    NameField.Clear();

so there's the code. I can't quite figure out why more than 2 submenu items is reason to ignore the eventhandler. Anyone see anything?? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Quote:

You *are* aware that array indexing is 0-based, yes?


Certainly :) The thing is, if i only "add" two submenus to the
NavigationMenu.MenuItems[2] menuitem, they each get their eventhandler as listed in the code...


tempMenu1.MenuItems.Add(tempNavPt.name, new EventHandler (NavPtClick_Deletion));
tempMenu2.MenuItems.Add(tempNavPt.name, new EventHandle(NavPtClick_Navigation));



however, as soon as I add the third submenu (it can be seen on the navigate options) and then try to click on it, nothing happens...

[Edited by - Boltimus on August 11, 2006 2:07:01 AM]

Share this post


Link to post
Share on other sites
I believe the error must be in your .add function... Are you sure you're resizing the array to fit all elements? And if using an unknown amount of elements, I would't be using list[nr] at all - use dynamic linked list instead.


#include <list.h>

class tempMenu
{
//...
list<submenu> submenus;
}

tempMenu tempMenu2;

void givemenu()
{
submenu newMenu;

//alter newMenu as you wish.

tempMenu2.MenuItems.submenus.push_back(newMenu);
}



As always, this is psuedocode. :)

Google for "stl list"!

/Robert

Share this post


Link to post
Share on other sites
I'm curious. Why:
tempMenu1.MenuItems.Add(tempNavPt.name, new EventHandler   
(NavPtClick_Deletion));
tempMenu2.MenuItems.Add(tempNavPt.name, new EventHandle
(NavPtClick_Navigation));

instead of:
tempMenu1.MenuItems.Add(tempNavPt.name, new EventHandler   
(NavPtClick_Deletion));
tempMenu2.MenuItems.Add(tempNavPt.name, new EventHandler //look here
(NavPtClick_Navigation));

I thought it was a typo at first but you've done it more than once. also how come it's not:
NavigationMenu.MenuItems[1].MergeType = MenuMerge.Replace;
NavigationMenu.MenuItems[1].MergeMenu(tempMenu2);
NavigationMenu.MenuItems[0].MergeMenu(tempMenu1);
NavigationMenu.MenuItems[0].Text = "Navigation";

as opposed to:
NavigationMenu.MenuItems[2].MergeType = MenuMerge.Replace;
NavigationMenu.MenuItems[2].MergeMenu(tempMenu2);
NavigationMenu.MenuItems[1].MergeMenu(tempMenu1);
NavigationMenu.MenuItems[1].Text = "Navigation";

Share this post


Link to post
Share on other sites
Quote:

I'm curious. Why:


Oh NO! I bet that is it. It was probably so late I didn't catch it, I'll check to make sure it isn't a typo, I sure hope it is!

Quote:

I thought it was a typo at first but you've done it more than once. also how come it's not:


I didn't include all the code, I was trying to be brief. But in the code I did not include there are other menu items.


Thanks for pointing out the spelling error!!

~Bolt

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement