请教高手您:在右键点击DataGridView的时候,让点击的行成为该DataGridView的CurrentRow.感谢!!

解决方案 »

  1.   

    lz: 解决办法如下:private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
    {
       if (e.Button == MouseButtons.Right)
       {
            //取得鼠标点击位置的信息,例如,行索引和列索引
            DataGridView.HitTestInfo info = dataGridView1.HitTest(e.X, e.Y);        //取得点击位置的行
            DataGridViewRow dgr = dataGridView1.Rows[info.RowIndex];
            //设置当前单元格,由于CurrentRow是只读属性,只有借助CurrentCell。 
            //必须将 CurrentCell 属性设置为所需行中的单元格。
            dataGridView1.CurrentCell=dgr.Cells[info.ColumnIndex];        //到此已经将点击的行成为该DataGridView的CurrentRow,下面让其处于选中状态,可以不用
            dataGridView1.Rows[info.RowIndex].Selected = true;
        }
    }
      

  2.   

    zestheart(零度经线) ,谢谢⌒⊙⊙⌒。
      

  3.   

    private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                if(e.Button==MouseButtons.Right)
                {
                    System.Drawing.Point pt = new Point(e.X, e.Y); 
                    DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt); 
                    if(hti.Type == DataGrid.HitTestType.Cell) 
                    { 
                        MessageBox.Show(dataGrid1[hti.Row, hti.Column].ToString()); 
                    } 
                }
            }
    也是可以的。
      

  4.   

    谢谢楼上的几位!特别感谢sdl2005lyx() !!