Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Append a MenuStrip to an MDI Parent Window (Windows Forms) c# (or) mdi child menu in wpf

In this post , I explained how to bind data to menu strip in Mdi Parent FORM. multiple-document interface (MDI) child window can be different from the Mdi Parent Window. For example, the MDI parent might be a spreadsheet, and the MDI child might be a chart. ,  I have used  stored procedures in this article.  I have binded the menu strip based on the role of the user.




using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
using Telerik.WinControls;
usingMicrosoft.ApplicationBlocks.Data;
usingSystem.Data.SqlClient;
usingSystem.Diagnostics;

namespace Company
{
    public partial class MainForm : Telerik.WinControls.UI.RadForm
    {
        publicMainForm()
        {
            InitializeComponent();
        }

        public DataSet getMenu()
        {
            returnSqlHelper.ExecuteDataset(Program.Con, CommandType.StoredProcedure, "Storedprocedute_Menu_Details");
        }

        public DataSet getWorkMenu(stringrole, int menu)
        {
            SqlParameter[] cmdpar = new SqlParameter[2];
            cmdparam[0] = new SqlParameter("@p_menu", SqlDbType.Int);
            cmdparam[0].Value = menuid;
            cmdparam[1] = new SqlParameter("@p_role", SqlDbType.Int);
            cmdparam[1].Value = roleId;
            returnSqlHelper.ExecuteDataset(Program.Con, CommandType.StoredProcedure, "StoredProcedure", cmdpar);
        }

        privatevoid SelectedChildMenu_OnClick(object sender, System.EventArgse)
        {
            if(((ActiveMdiChild != null))) ActiveMdiChild.Close();
            cmbNames.SelectedValue = sender.ToString();
            stringformName = cmbNames.Text;
            string[] frms = formName.Split('&');

            objectoForm = new object();
            Program.frmName = frms[0];
            Program.mode = frms[1];
            stringprojName = "Company";
            TypetForm = System.Reflection.Assembly.GetExecutingAssembly().GetType(projName + "." + frms[0]);

            if(Program.frmName == "Calculator")
            {
                Process.Start("C:\\WINDOWS\\system32\\calc.exe");
            }
            elseif (((tForm != null)))
            {
                oForm = Activator.CreateInstance(tForm);
                ((Form)oForm).MdiParent = this;
                ((Form)oForm).Show();
            }
        }

        public void MainForm_Load(objectsender, EventArgs e)
        {
            MenuStrip2.Items.Clear();
            ToolStripMenuItemchildItem = default(ToolStripMenuItem);
            intcnt = 0;
            DataSetmenuData = null;
            menuData = getMenu();
            cmbFuncNames.DataSource = menuData.Tables[1];
            cmbFuncNames.DisplayMember = "progam";
            cmbFuncNames.ValueMember = "work";
            for(int j = 0; j <= menuData.Tables[0].Rows.Count - 1; j++)
            {
                intid = Convert.ToInt32(menuData.Tables[0].Rows[j]["MENUID"]);
                ToolStripMenuItemparItem = new ToolStripMenuItem();
                parItem.Name = id.ToString();
                stringmenuName = menuData.Tables[0].Rows[j]["MENUNAME"].ToString();
                parItem.Text = menuName;                 MenuStrip2.Items.Add(parItem);
                DataSetchildDs = new DataSet();
                childDs = getWorkMenu(Program.userrole, id);
                ContextMenuStripcms = new ContextMenuStrip();
                for(int i = 0; i <= childDs.Tables[0].Rows.Count - 1; i++)
                {
                    childItem = new ToolStripMenuItem();
                    childItem.ForeColor = System.Drawing.Color.Black;
                    childItem.Name = childDs.Tables[0].Rows[i]["WorkID"].ToString();
                    childItem.Text = childDs.Tables[0].Rows[i]["WorkNAME"].ToString();
                    childItem.Tag = childDs.Tables[0].Rows[i]["PROG_NAME"].ToString();
                    parItem.DropDownItems.Add(childItem);

                    cms.Items.Add(childItem.Text, null, new System.EventHandler(SelectedChildMenu_OnClick));
                }
                ToolStripMenuItemtsi = (ToolStripMenuItem)parItem;
                tsi.DropDown = cms;
            }
        }

        privatevoid MainForm_FormClosing(object sender, FormClosingEventArgse)
        {
            Application.Exit();
        }

        privatevoid MenuStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgse)
        {
            if(e.ClickedItem.Text == "close")
            {
                Application.Exit();
            }
        }
    }
}




This post first appeared on Asp.netSourceCodes, please read the originial post: here

Share the post

Append a MenuStrip to an MDI Parent Window (Windows Forms) c# (or) mdi child menu in wpf

×

Subscribe to Asp.netsourcecodes

Get updates delivered right to your inbox!

Thank you for your subscription

×