我写了一个菜单项,当点击右键时 对dataGrid中某一行的数据进行编辑,dataGrid中当点击鼠标右键时 并不能选中一行数据, 希望得到大家的帮助

解决方案 »

  1.   

    private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    this.dataGridView1.CurrentCell = this.dataGridView1[e.ColumnIndex, e.RowIndex];
                }
            }
      

  2.   

    在winfrom 中选择datagrid的mouseup事件写入代码: this.datagrid1.select(this.datagrid1.currentrowindex)
      

  3.   

    各位前辈我试的怎么不行啊
    在WinForm 中找不到这个事件啊!
    private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    this.dataGridView1.CurrentCell = this.dataGridView1[e.ColumnIndex, e.RowIndex];
                }
            }
      

  4.   

    不是不行,而是你没有区分大小写呀,在C#中是有大小写区分的
    你试试this.DataGrid1.select(this.DataGrid1.CurrentRowIndex)
      

  5.   

    private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {
         Point pt = new Point(e.X,e.Y);
    DataGrid.HitTestInfo hit = dataGrid1.HitTest(pt);
    if(hit.Type == DataGrid.HitTestType.Cell) 
    {
    dataGrid1.Select(hit.Row); 
    }
        }

    }
      

  6.   

    DataGrid.HitTestInfo hit = this.dataGrid.HitTest(e.X,e.Y) ; if(hit != null && hit.Type == DataGrid.HitTestType.Cell)
    {
    if(e.Button==System.Windows.Forms.MouseButtons.Right)
    {
    this.dataGrid.CurrentRowIndex = hit.Row ;
    this.m_ContextMenu.Show(this.dataGrid,new Point(e.X,e.Y)) ;
    }
    }