I have a datagridview with five columns and context menu strip which have items and sub items. When I right click on last column I want to open context menu.
I tried this code, but it's open context menu strip without sub items.
dataGrid.Columns[dataGrid.Columns.Count].HeaderCell.ContextMenuStrip = contextMenuStrip1;
Best Answer
It looks like you want to open your ContextMenuStrip if your user right clicks the header of your DataGridView's last column. I would use the DataGridView
MouseDown
event and in that event check for these conditions and if they're met call theShow
method of your ContextMenuStrip.Like this: