0

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?

Infoservice
  • 107
  • 4
  • 16

2 Answers2

1

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;
...
Taysumi
  • 291
  • 2
  • 16
  • This is my code (from my post): cbC.ContextMenuStrip = mymenu;(is a ContextMenuStrip) This is the your code; this.Column1.ContextMenuStrip = this.contextMenuStrip1; Where is the difference? – Infoservice Dec 27 '16 at 15:03
  • @Frank - Did you try adding it via GUI? This way it should work. The only difference I see is that you don't have `this.` ... – Taysumi Dec 27 '16 at 16:01
0

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

DataGridViewColumn.ContextMenuStrip propriété

Thomas
  • 7
  • 2