Click here to Skip to main content
15,888,162 members
Articles / Programming Languages / XML

Dynamic MainMenu Formation in Winform Application using XML - Part 2

Rate me:
Please Sign up or sign in to vote.
3.36/5 (11 votes)
7 Feb 2004 75.4K   560   30   12
Dynamic MainMenu formation in Winform application using XML

Introduction

In my previous article, I explained how we can form a dynamic menu using XML. That is a very basic method. There we cannot do any validation like MenuItem enable or disable, icon setting, etc. In this article, I extend the XML usage.

Building Menu

I have changed the XML format. The following is the XML file format:

XML
<Records>
<MenuItem>
<MenuID>FILE</MenuID>
<MenuName>File</MenuName>
<MenuParent></MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>NEW</MenuID>
<MenuName>New</MenuName>
<MenuParent>FILE</MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>OPEN</MenuID>
<MenuName>Open</MenuName>
<MenuParent>FILE</MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>EXIT</MenuID>
<MenuName>Exit</MenuName>
<MenuParent>FILE</MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>DOC</MenuID>
<MenuName>Document File</MenuName>
<MenuParent>NEW</MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>TXT</MenuID>
<MenuName>Text File</MenuName>
<MenuParent>NEW</MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>HTML</MenuID>
<MenuName>HTML File</MenuName>
<MenuParent>NEW</MenuParent>
<Enable>N</Enable>
</MenuItem>
<MenuItem>
<MenuID>EDIT</MenuID>
<MenuName>Edit</MenuName>
<MenuParent></MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>COPY</MenuID>
<MenuName>Copy</MenuName>
<MenuParent>EDIT</MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>PASTE</MenuID>
<MenuName>Paste</MenuName>
<MenuParent>EDIT</MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>HELP</MenuID>
<MenuName>Help</MenuName>
<MenuParent></MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>HHELP</MenuID>
<MenuName>Help</MenuName>
<MenuParent>HELP</MenuParent>
<Enable>Y</Enable>
</MenuItem>
<MenuItem>
<MenuID>ABOUT</MenuID>
<MenuName>About</MenuName>
<MenuParent>HELP</MenuParent>
<Enable>Y</Enable>
</MenuItem>
</Records>

I have changed the CreateMenuItems a little bit to use DataSet.

Code

The menu will be shown like:

Menu Design

Finally

I think this shows how you can implement the security in MainMenu and any help and/or comments are much appreciated!

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Web Developer
United States United States
Amalorpavanathan Yagulasamy (AMAL) is a Software Engineer for Protech Solution Inc. and has designed and implemented projects for Arkansas Child Support, Arkansas Budgetting, Michigan Child Support , Massachusetts Child Support, National Informatics Center-India and Indian Oil Corporation. His background is in developing relational databases and n-tier applications on Windows platforms in CMM Level Standards. He can be reached at amal_forum@hotmail.com

Comments and Discussions

 
GeneralYes,Very Useful Pin
chinesedragon4-Dec-09 14:48
chinesedragon4-Dec-09 14:48 
GeneralSeperator in Menu Pin
Gaurav Rathod9-Nov-04 18:19
Gaurav Rathod9-Nov-04 18:19 
QuestionWebForm instead of WinForm? Pin
Anonymous16-Jun-04 17:24
Anonymous16-Jun-04 17:24 
QuestionPrevious article? Pin
netclectic10-Feb-04 3:39
netclectic10-Feb-04 3:39 
GeneralThoughs about the XML syntax Pin
Rui Dias Lopes9-Feb-04 12:43
Rui Dias Lopes9-Feb-04 12:43 
GeneralRe: Thoughs about the XML syntax Pin
Amalorpavanathan Yagulasamy(AMAL)10-Feb-04 7:23
Amalorpavanathan Yagulasamy(AMAL)10-Feb-04 7:23 
GeneralRe: Thoughs about the XML syntax Pin
b0ksah19-Mar-07 3:38
b0ksah19-Mar-07 3:38 
QuestionWhat is the advantage of dynamic mainmenu? Pin
Kilo0009-Feb-04 3:52
Kilo0009-Feb-04 3:52 
AnswerRe: What is the advantage of dynamic mainmenu? Pin
Amalorpavanathan Yagulasamy(AMAL)9-Feb-04 7:47
Amalorpavanathan Yagulasamy(AMAL)9-Feb-04 7:47 
i will explain the usage and implementation of dynamic mainmenu later.

You can bind the Click event like,
MenuItem mmru = new MenuItem(GetMenuName(strMenu) , new EventHandler(Menu_Click));
mnuItem.MenuItems.Add(mmru);

i have give the way for binding the Click event dynamically in source code.
you can see there.

Also you can use a single click event for muitiple purpose, using the following way,
private void Menu_Click(object sender, System.EventArgs e)
{
switch (((MenuItem) sender).Text.ToUpper())
{
case "TXT" :
//write your code here for New Text file action
MessageBox.Show("You clicked - Text File");
break;
case "OPEN" :
//write your code here for Open action
MessageBox.Show("You clicked - Open");
break;
case "EXIT" :
this.Close();
break;
}
}

Regards,
Amal
amal_forum@hotmail.com
GeneralRe: What is the advantage of dynamic mainmenu? Pin
aatanw28-Jun-04 22:37
aatanw28-Jun-04 22:37 
GeneralMight I suggest... Pin
Marc Clifton8-Feb-04 10:21
mvaMarc Clifton8-Feb-04 10:21 
GeneralRe: Might I suggest... Pin
Amalorpavanathan Yagulasamy(AMAL)8-Feb-04 12:04
Amalorpavanathan Yagulasamy(AMAL)8-Feb-04 12:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.