|
By default, the ContextMenuStrip will open only on the right click over the associated control. If the cell is in edit mode then the cell will no longer receives mouse related events. Only the control(TextBox or ComboBox) present inside the cell will receive the mouse events. So to have a ContextMenuStrip in the Edit mode you need to set the ContextMenuStrip for those control present inside the cell. This can be achieved by handling the events CurrentCellControlGotFocus, CurrentCellControlLostFocus and MouseDown event. Here is the code snippets: C# void gridControl1_CurrentCellControlLostFocus(object sender, ControlEventArgs e) { e.Control.MouseDown -= new MouseEventHandler(Control_MouseDown); } void Control_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) this.contextMenuStrip1.Show(Control.MousePosition.X, Control.MousePosition.Y); } void gridControl1_CurrentCellControlGotFocus(object sender, ControlEventArgs e) { e.Control.MouseDown += new MouseEventHandler(Control_MouseDown); } VB Private Sub gridControl1_CurrentCellControlLostFocus(ByVal sender As Object, ByVal e As ControlEventArgs) RemoveHandler e.Control.MouseDown, AddressOf Control_MouseDown End Sub Private Sub Control_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) If e.Button = MouseButtons.Right Then Me.contextMenuStrip1.Show(Control.MousePosition.X, Control.MousePosition.Y) End If End Sub Private Sub gridControl1_CurrentCellControlGotFocus(ByVal sender As Object, ByVal e As ControlEventArgs) AddHandler e.Control.MouseDown, AddressOf Control_MouseDown End Sub Please refer the sample in the link to illustrate this: http://websamples.syncfusion.com/samples/KB/Grid.Windows/GridContextMenu/Main.htm |