I m new in c#.net, i m working on project which generate menu dynamically, i have done this point, but not retrieve menu text at menu click, i just want to get text of menu.
my code is follows:
namespace myProg
{
public partial class frmMenu : Form
{
DataTable DtMenu;
MenuStrip MainMenu = new MenuStrip();
ToolStripMenuItem PopUpMenu = new ToolStripMenuItem();
ToolStripMenuItem SubMenu = new ToolStripMenuItem();
ToolStripMenuItem BarMenu = new ToolStripMenuItem();
public frmMenu()
{
InitializeComponent();
}
private void frmMenu_Load(object sender, EventArgs e)
{
CreateMainMenu();
}
private void CreatePopUpMenu(MenuStrip mMenu, string mPopUpName)
{
PopUpMenu = new ToolStripMenuItem(mPopUpName);
PopUpMenu.Text = mPopUpName;
PopUpMenu.TextAlign = ContentAlignment.BottomRight;
mMenu.Items.Add(PopUpMenu);
}
private void CreateSubMenu(ToolStripMenuItem mPopUpName, string mBarName)
{
SubMenu = new ToolStripMenuItem(mBarName);
SubMenu.Text = mBarName;
SubMenu.TextAlign = ContentAlignment.BottomRight;
mPopUpName.DropDown.Items.Add(SubMenu);
}
private void CreateBarMenu(ToolStripMenuItem mPopUpName, string mBarName, MenuStrip mMenu, Int32 mMenuId)
{
BarMenu = new ToolStripMenuItem(mBarName);
BarMenu.TextAlign = ContentAlignment.BottomRight;
BarMenu.Tag = Convert.ToInt32(mMenuId);
BarMenu.Text = mBarName;
mPopUpName.DropDown.Items.Add(BarMenu);
BarMenu.Click += new System.EventHandler(this.FileMenuItemClick);
}
private void CreateMainMenu()
{
Int32 mTagId = 0;
Int32 mLastTagId = 0;
Int32 mSubMenu = 0; // 0=No, 1=Yes
string mPopName = "";
string mSubName = "";
string mBarName = "";
Users ObjUsers = new Users();
DtMenu = ObjUsers.GetMainMenu();
try
{
if (DtMenu.Rows.Count > 0)
{
this.MainMenuStrip = MainMenu;
MainMenu.Name = "MainMenu";
MainMenu.Dock = DockStyle.Top;
Controls.Add(MainMenu);
for (int m_For = 0; m_For < DtMenu.Rows.Count; m_For++)
{
if (Convert.ToInt32(DtMenu.Rows[m_For]["tagid"]) != mTagId)
{
mTagId = Convert.ToInt32(DtMenu.Rows[m_For]["tagid"]);
if (mTagId != mLastTagId)
{
mLastTagId = mTagId;
if (mTagId == 1)
mPopName = "Setup";
else
mPopName = "Transaction";
mSubName = "";
mBarName = "";
PopUpMenu = new ToolStripMenuItem();
SubMenu = new ToolStripMenuItem();
BarMenu = new ToolStripMenuItem();
}
CreatePopUpMenu(MainMenu, mPopName);
if (Convert.ToInt32(DtMenu.Rows[m_For]["SubMenuOrClick"]) == 0)
{
mSubName = Convert.ToString(DtMenu.Rows[m_For]["BarDesc"]);
CreateSubMenu(PopUpMenu, mSubName);
}
else
{
mBarName = Convert.ToString(DtMenu.Rows[m_For]["BarDesc"]);
if (SubMenu.Name == "")
CreateBarMenu(PopUpMenu, mBarName, MainMenu, Convert.ToInt32(DtMenu.Rows[m_For]["menuid"]));
else
CreateBarMenu(SubMenu, mBarName, MainMenu, Convert.ToInt32(DtMenu.Rows[m_For]["menuid"]));
}
}
else
{
if (Convert.ToInt32(DtMenu.Rows[m_For]["SubMenuOrClick"]) == 0)
{
mSubName = Convert.ToString(DtMenu.Rows[m_For]["BarDesc"]);
if (PopUpMenu.DropDown.Items.Count > 0 && SubMenu.DropDown.Items.Count > 0)
CreateSubMenu(SubMenu, mSubName);
else
CreateSubMenu(PopUpMenu, mSubName);
}
else
{
mBarName = Convert.ToString(DtMenu.Rows[m_For]["BarDesc"]);
CreateBarMenu(SubMenu, mBarName, MainMenu, Convert.ToInt32(DtMenu.Rows[m_For]["menuid"]));
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void FileMenuItemClick(object sender, EventArgs e)
{
i have problem here, i just want tag value of selected bar, please help me
}
}
}