We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

GridGroupingControl how to get a context menu with Cut/Copy/Paste for the activated cell

For a GridGroupingControl, I would like to be able to show a context menu(with Cut, Copy, Paste) if the active cell is a TextBox when the user performs a right click. 

How can I achieve this?

Thanks for your help!

3 Replies

SA Solai A L Syncfusion Team July 13, 2015 05:50 AM UTC

Hi Taylour,

Thank you for your interest in Syncfusion products.

In order to add a context menu, you can it in cell edit mode while the TableControlGotFocus. Please refer the below UG link for reference.

UG Link :
http://help.syncfusion.com/ug/windows%20forms/index.html#!Documents/howtoattachacontextmenutoacellingridgroupingcontrol.htm

Please refer the below KB and installed location sample to add copy paste option in context menu.

KB Link :
https://www.syncfusion.com/kb/4672/how-to-use-your-own-context-menu-along-with-the-fieldchooser-option

Sample Link :
<Installed Location>\Syncfusion\EssentialStudio\<Version?\Windows\Grid.Grouping.Windows\Samples\Layout Customization\Cut-Copy-Paste Demo\cs

Please let us know if you have any other concerns.

Thanks & Regards,
AL.Solai.


TT tttmack July 13, 2015 10:50 PM UTC

thanks but that method did not work in my case.

I was able to get things working with the following code:

private ContextMenuStrip _contextMenuStrip;

public Form1()
{
            _contextMenuStrip = new ContextMenuStrip();
            _contextMenuStrip.Items.Add("Cut", Properties.Resources.Cut, GridCutContextMenu);
            _contextMenuStrip.Items.Add("Copy", Properties.Resources.Copy, GridCopyContextMenu);
            _contextMenuStrip.Items.Add("Paste", Properties.Resources.Paste, GridPasteContextMenu);

            var textRenderer = gridGroupingControl1.TableControl.CellRenderers["TextBox"] as GridTextBoxCellRenderer;
            textRenderer.TextBox.MouseUp += GridGroupingControlTextBox_MouseUp;
}

void GridGroupingControlTextBox_MouseUp(object sender, MouseEventArgs e)
{
            if(e.Button == MouseButtons.Right)
                _contextMenuStrip.Show(Cursor.Position);
}

private void GridCutContextMenu(object sender, EventArgs e)
{
            gridGroupingControl1.TableModel.CutPaste.Cut();
}

private void GridCopyContextMenu(object sender, EventArgs e)
{
            gridGroupingControl1.TableModel.CutPaste.Copy();
}

private void GridPasteContextMenu(object sender, EventArgs e)
{
            gridGroupingControl1.TableModel.CutPaste.Paste();
}






SA Solai A L Syncfusion Team July 14, 2015 11:13 AM UTC

Hi Taylour,

Thank you for your update.

We are glad to know that your issue has been resolved. Please let us know if you have any other further concerns in future.

Thanks & Regards,
Al.Solai.

Loader.
Live Chat Icon For mobile
Up arrow icon