Monday, February 23, 2015

Adding Content Menu and Custom Menu items on a tree node - Windows Application using C#

This code shows how you can add a context menu with the context menu items to your window application on a tree node.

ToolStripMenuItem siteSettings = new ToolStripMenuItem();
            siteSettings.Text = "Site Settings";
            siteSettings.BackColor = Color.AliceBlue;
            siteSettings.Image = imageList1.Images[5];

            ToolStripMenuItem lstContentTypeReport = new ToolStripMenuItem();
            lstContentTypeReport.Text = "Lists Content Types";
            lstContentTypeReport.BackColor = Color.AliceBlue;
            lstContentTypeReport.Image = imageList1.Images[5];

            ToolStripMenuItem treeStructure = new ToolStripMenuItem();
            treeStructure.Text = "Site Structure";
            treeStructure.BackColor = Color.AliceBlue;
            treeStructure.Image = imageList1.Images[15];


            ToolStripMenuItem manageAuditSettings = new ToolStripMenuItem();
            manageAuditSettings.Text = "Manage Audit Settings";
            manageAuditSettings.BackColor = Color.AliceBlue;
            manageAuditSettings.Image = imageList1.Images[15];

            ToolStripMenuItem manageSPAlerts = new ToolStripMenuItem();
            manageSPAlerts.BackColor = Color.AliceBlue;
            manageSPAlerts.Text = "Manage ShaerPoint Alerts";
            manageSPAlerts.Image = imageList1.Images[14];

            ToolStripMenuItem addUsers = new ToolStripMenuItem();
            addUsers.Text = "Add Users";
            addUsers.BackColor = Color.AliceBlue;
            addUsers.Image = imageList1.Images[13];

            ToolStripMenuItem siteStorageAnalysis = new ToolStripMenuItem();
            siteStorageAnalysis.Text = "Site Storage Analysis";
            siteStorageAnalysis.BackColor = Color.AliceBlue;
            siteStorageAnalysis.Image = imageList1.Images[12];

            ToolStripMenuItem sitePemissions = new ToolStripMenuItem();
            sitePemissions.Text = "Site Permissions";
            sitePemissions.BackColor = Color.AliceBlue;
            sitePemissions.Image = imageList1.Images[11];

            ToolStripMenuItem findUserSecurity = new ToolStripMenuItem();
            findUserSecurity.Text = "Find User Security";
            findUserSecurity.BackColor = Color.AliceBlue;
            findUserSecurity.Image = imageList1.Images[10];
            contextMenuStrip2.Items.AddRange(new ToolStripMenuItem[] { siteSettings, lstContentTypeReport, manageAuditSettings, treeStructure, manageSPAlerts, addUsers });
            contextMenuStrip2.Items.Add(new ToolStripSeparator());
            contextMenuStrip2.Items.AddRange(new ToolStripMenuItem[] { siteStorageAnalysis, sitePemissions, findUserSecurity });



                Treenode Control:


                         TreeNode Groups = new TreeNode("Sites");                     
                  

                        Groups.ContextMenuStrip = groupContextMenu;

No comments: