Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

ContextMenuStrip isn't showing on the first time

$
0
0

Hi,

I got this part of code, where I open contextMenuStrip in respond to mouse right-click (over dataGridView table).

The problem is, that the FIRST TIME i right click - the menu doesn't pop up. On the second time it pops up, and since then everything is working well..

        private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
        {
            DataGridView.HitTestInfo info = dataGridView1.HitTest(e.X, e.Y); //get click position inforamtion
            int currentMouseOverRow = dataGridView1.HitTest(e.X, e.Y).RowIndex;
            
               if (e.Button == MouseButtons.Right) //MouseButton right: Open context menu strip.
                {
                    dataGridView1.Rows[currentMouseOverRow].Selected = true; //Select the row there was right-click on

                    ContextMenuStrip Menu = new ContextMenuStrip();
                    ToolStripMenuItem MenuOpenPO = new ToolStripMenuItem("Delete it");
                    MenuOpenPO.Click += new EventHandler(MenuOpenPO_Click);
                    Menu.Items.AddRange(new ToolStripItem[] { MenuOpenPO });
                    dataGridView1.ContextMenuStrip = Menu; //Assign created context menu strip to the DataGridView
                }
           

        }

Any help ? :) I use visual studio 2012.

Thanks!

Eyal.


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>