Data Grid WinForms Control Create data gird view in C# with modern user interface for your Windows Forms applications Custom Context Menus of Grid in C#
The Kettic Data Grid Control offers an easy way to build custom context menus in grid view to replace the default menus. When users of the Kettic Grid Control right click the control, the context menu will display, regardless of the grid control element. Create Custom Context Menu
To create the custom context menu, we need to initialize the items of custom context menus, and then subscribe for the events that you are going to handle to achieve desired behavior. In the process of creating custom context menu, we will need to add the Kettic WinForms.UI.Control namespace to your C# project. private KetticContextMenu contextMenu; private void Form1_Load(object sender, EventArgs e) { contextMenu = new KetticContextMenu(); KetticMenuItem menuItem1 = new KetticMenuItem("Item 1"); menuItem1.ForeColor = Color.Blue; menuItem1.Click += new EventHandler(menuItem1_Click); KetticMenuItem menuItem2 = new KetticMenuItem("Item 2"); menuItem2.Click += new EventHandler(menuItem2_Click); contextMenu.Items.Add(menuItem1); contextMenu.Items.Add(menuItem2); }
When we initialize and populate the menu object with menu items, the menu object will be attached to the Data Grid Control. This requires us subscribe to the ContextMenuOpening event and display the context menu. void ketticGrid_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e) { e.ContextMenu = contextMenu.DropDown; }
Create Custom Context Menu to GridView in C# |