Right click to select row in dataGridView

前端 未结 4 2132
一个人的身影
一个人的身影 2020-12-29 10:31

I need to select a row in dataGridView with right click before ContextMenu shown because contextMenu is row-dependendt.

I\'ve tried this:

 if (e.Butt         


        
4条回答
  •  灰色年华
    2020-12-29 11:17

     if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                var hti = GridView.HitTest(e.X, e.Y);
                GridView.ClearSelection();
    
                int index = hti.RowIndex;
    
                if (index >= 0)
                {
                    GridView.Rows[hti.RowIndex].Selected = true;
                    LockFolder_ContextMenuStrip.Show(Cursor.Position);
                }
    
            }
    

    This is Accurate Method i Guess

提交回复
热议问题