2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Add ContextMenuStrip to the gridIn order to show the ContextMenu in grid cells on right click, the ContextMenuStrip property of grid can be used and the ToolStripMenu items can be added to Items collection of ContextMenuStrip. Initializing ContextMenu C# ContextMenuStrip contextMenuStrip1 = new ContextMenuStrip(); // copyToolStripMenuItem1 ToolStripMenuItem copyToolStripMenuItem1 = new ToolStripMenuItem(); this.copyToolStripMenuItem1.Name = "copyToolStripMenuItem1"; this.copyToolStripMenuItem1.Size = new System.Drawing.Size(175, 24); this.copyToolStripMenuItem1.Text = "Copy"; //Adding toolstrip menu items to context menu this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.copyToolStripMenuItem1, this.editToolStripMenuItem, this.findToolStripMenuItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Size = new System.Drawing.Size(176, 104); VB Private contextMenuStrip1 As New ContextMenuStrip() ' copyToolStripMenuItem1 Dim copyToolStripMenuItem1 As New ToolStripMenuItem() Me.copyToolStripMenuItem1.Name = "copyToolStripMenuItem1" Me.copyToolStripMenuItem1.Size = New System.Drawing.Size(175, 24) Me.copyToolStripMenuItem1.Text = "Copy" 'Adding toolstrip menu items to context menu Me.contextMenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() { Me.copyToolStripMenuItem1, Me.editToolStripMenuItem, Me.findToolStripMenuItem}) Me.contextMenuStrip1.Name = "contextMenuStrip1" Me.contextMenuStrip1.Size = New System.Drawing.Size(176, 104) Adding ContextMenu to grid GridControl C# //Add the context menu to the grid this.gridControl1.ContextMenuStrip = contextMenuStrip1; //Event triggering this.copyToolStripMenuItem1.Click += new System.EventHandler(this.copyToolStripMenuItem1_Click); //Event Customization private void copyToolStripMenuItem1_Click(object sender, EventArgs e) { //Code to perform actions on context menu item click GridCurrentCell currentCell = this.gridControl1.CurrentCell; Clipboard.SetText(this.gridControl1[currentCell.RowIndex, currentCell.ColIndex].CellValue.ToString()); } VB 'Add the context menu to the grid Me.gridControl1.ContextMenuStrip = contextMenuStrip1 'Event triggering AddHandler copyToolStripMenuItem1.Click, AddressOf copyToolStripMenuItem1_Click 'Event Customization private void copyToolStripMenuItem1_Click(Object sender, EventArgs e) 'Code to perform actions on context menu item click Dim currentCell As GridCurrentCell = Me.gridControl1.CurrentCell Clipboard.SetText(Me.gridControl1(currentCell.RowIndex, currentCell.ColIndex).CellValue.ToString()) GridGroupingControl C# //Adding ContextMenuStrip to the Grid. this.gridGroupingControl1.ContextMenuStrip = contextMenuStrip1; //Event Triggering this.copyToolStripMenuItem.Click += new System.EventHandler(this.copyToolStripMenuItem_Click); //Event Customization private void copyToolStripMenuItem_Click(object sender, EventArgs e) { //Code to perform actions on context menu item click int index = this.gridGroupingControl1.TableControl.GetClientCol(this.gridGroupingControl1.TableControl.CurrentCell.ColIndex); string columnName = this.gridGroupingControl1.TableDescriptor.Columns[index].Name; Record currentRecord = this.gridGroupingControl1.Table.CurrentRecord; Clipboard.SetText(currentRecord.GetValue(columnName).ToString()); } VB 'Adding ContextMenuStrip to the Grid. Me.gridGroupingControl1.ContextMenuStrip = contextMenuStrip1 'Event Triggering AddHandler copyToolStripMenuItem.Click, AddressOf copyToolStripMenuItem_Click 'Event Customization private void copyToolStripMenuItem_Click(Object sender, EventArgs e) 'Code to perform actions on context menu item click Dim index As Integer = Me.gridGroupingControl1.TableControl.GetClientCol(Me.gridGroupingControl1.TableControl.CurrentCell.ColIndex) Dim columnName As String = Me.gridGroupingControl1.TableDescriptor.Columns(index).Name Dim currentRecord As Record = Me.gridGroupingControl1.Table.CurrentRecord Clipboard.SetText(currentRecord.GetValue(columnName).ToString()) Screenshot GridControl GridGroupingControl Samples: GridControl GridGroupingControl |
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.