Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Table Driven Menus
Message
De
19/11/2009 09:56:36
 
 
À
19/11/2009 01:09:28
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01435073
Message ID:
01435585
Vues:
53
>Bernard,
>
>Sorry I didn't flesh it out a little more, but basically what you would do, instead of simply adding a plain old MenuItem, you could have a set of MenuItem sub-classes that would do the work of handling the click event (and any icons you want). For example, I have a menu that allows the user to have a list of Favorites to browse to, so my FavoritesMenuItem looks something like this:
>
>public class FavoritesMenuItem : MenuItem
>{
>	protected string URL = "";
>
>	public FavoritesMenuItem(string text, string link) : base(text)
>	{
>		this.Click += new System.EventHandler(this.ClickHandler);
>		this.URL = link;
>		// this is where you'd do icons too, I don't have any
>	}
>
>
>	#region Events
>	protected virtual void ClickHandler(object sender, System.EventArgs e)
>	{
>		// code here for handling the menu item click to browse the URL
>	}
>	#endregion
>}
>
>
>Then of course, you'd add them like this:
>
>private void TestMenuAddItemsDynamically()
>{
>	MenuItem item; // leave it this way so you can have other item sub-classes
>	foreach (DataRow row in this.oData.Rows)
>	{
>		if ((bool)row["IsFavorites"] == true)
>		{
>		    item = new FavoritesMenuItem(row["description"].ToString(), row["url"].ToString());
>		    this.AddMenuItem("Favorites", item);
>		}
>		else
>		{
>		    item = new MyOtherMenuItem(row["description"].ToString());
>		    this.AddMenuItem("Dynamic Menu", item);
>		}
>	}
>}
>
>
>Does this help?
>
>~~Bonnie
>

Hi Bonnie

Thanks, Yes that does.

I have just one more question if you don't mind.

Coming from a VFP background that is all I have to fall back on, so I will describe how i'd do it in VFP as I don't know how to do it in .Net.

Say I create this app(exe) with a menu and ship it out. Now the user wants to add some more functionality so since my menu is datadriven, I create an additional .APP with the needed forms/code compiled. Then I just add a record into the menu table to give the menu a name and location, an icon (maybe) and the name of the app is added to another field. So when the user runs the original app, the dynamic menu code sees the new line and creates a new menu item, setting the additional APP file to run on the menu item being clicked.

Now I have added functionality to the original application without recompiling.

So could I do that in .NET and just ship an additional exe or dll and add this extra functionality to my original app just by adding a lrecord into the table that drives the menu?

The code you showed above will do what I ask for sure, but will I have to recompile the whole application again and include the class referenced in the new menu item or can I just compile the above class into a dll and ship only that after adding a record to the table?
That would really be dynamic then.

I hope I have described this situation properly.

Thanks

Bernard
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform