Skip to content

SyncfusionExamples/how-to-disable-the-context-menu-for-the-textbox-in-edit-mode-in-winforms-datagrid

Repository files navigation

How to disable the context menu for the textbox in edit mode in WinForms DataGrid?

About the sample

This example illustrates how to disable the context menu for the textbox in edit mode in WinForms DataGrid.

In WinForms DataGrid (SfDataGrid), ContextMenu can be disabled for a TextBox in edit mode by deriving a new class from GridTextBoxCellRenderer and overriding the OnWireEditUIElement while assigning an empty context menu into the ContextMenu property of TextBox.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        //Remove existing TextBox Renderer
        sfDataGrid.CellRenderers.Remove("TextBox");
        //Add customized TextBox Renderer
        sfDataGrid.CellRenderers.Add("TextBox", new GridTextBoxCellRendererExt());
    }
}
public class GridTextBoxCellRendererExt : GridTextBoxCellRenderer
{
    protected override void OnWireEditUIElement(TextBox uiElement)
    {
        base.OnWireEditUIElement(uiElement);
        //To prevent the default context menu of a TextBox from showing up, assign a empty context menu as shown below
        uiElement.ContextMenu = new ContextMenu();
    }
} 

Note: This can also be done for GridNumericColumn by deriving a new class from GridNumericCellRenderer.

Take a moment to peruse the WinForms DataGrid - Customize Column Renderer documentation, where you can find about customize column renderer with code examples.

Requirements to run the demo

Visual Studio 2015 and above versions

About

How to disable the context menu for the textbox in edit mode in WinForms DataGrid (SfDatGrid)?

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages