How do I correctly position a Context Menu when I right click a DataGridView’s column header?

Here is a very simple way to make context menu appear where you right-click it.

Handle the event ColumnHeaderMouseClick

private void grid_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) 
{
  if (e.Button == System.Windows.Forms.MouseButtons.Right)
    contextMenuHeader.Show(Cursor.Position);
}

contextMenuHeader is a ContextMenuStrip that can be defined in the Designer view or at runtime.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)