DataGridViewComboBoxColumn and ContextMenuStrip

52 views Asked by At

I have this partial code:

        DataGridViewComboBoxColumn cbC = new DataGridViewComboBoxColumn();
        cbC.HeaderText = "Code:";
        cbC.Name = "code";
        cbC.ContextMenuStrip = mymenu;(is a ContextMenuStrip)

I click with right mouse button on the row but the menu not showing, what's wrong?

2

There are 2 answers

2
Habbi On

In your DataGridView properties, there is an option called "ContextMenuStrip" (at "Behavior"). Select your ContextMenuStrip and it should work.
property screenshot

Alternatively you can add this line of code in the designer (not recommended!):

//
// dataGridView1
//
...
this.dataGridView1.ContextMenuStrip = this.contextMenuStrip1
...

EDIT
This way the ContextMenu is everywhere. You can add it for each column seperately by right-clicking the DataGridView (in the editor) and then "Edit Columns...".
As before you can add it in the designer via code (also not recommended):

// 
// Column1
// 
this.Column1.ContextMenuStrip = this.contextMenuStrip1;
...
0
Thomas On

You should have a look here, you will find the answer :)

DataGridViewColumn.ContextMenuStrip propriété