Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DataGridView - Remove default context menu while editing cell

$
0
0

I have read multiple post about using EditingContolShowing event to prevent the default context menu from appearing on a right click in the cell that you are editing. But how can I prevent this default menu from appearing when the user has right clicked and holds the button down in the editing cell,then drags the mouse out of the cell and releases the mouse button. When you release the mouse button over another cell you get the Default Context menu. Any suggestions?

Below is code for a Form with a dataGridView on it.  

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string[] Row = new string[] {"1", "First Comment"};
            dataGridView1.Rows.Add(Row);

            Row = new string[] {"2", ""};
            dataGridView1.Rows.Add(Row);

            Row = new string[] {"3", ""};
            dataGridView1.Rows.Add(Row);
        }

        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            e.Control.ContextMenu = new ContextMenu();
        }
    }

 

Viewing all articles
Browse latest Browse all 2535

Trending Articles