选择datagridview 单元格时如何获取单元的坐标?(就是 x,y 的值  我要代码详细的啊)急急!
(有实例更好)

解决方案 »

  1.   


    private void getCurrentCellButton_Click(object sender, System.EventArgs e)
    {
        string msg = String.Format("Row: {0}, Column: {1}",
            dataGridView1.CurrentCell.RowIndex,
            dataGridView1.CurrentCell.ColumnIndex);
        MessageBox.Show(msg, "Current Cell");
    }
    这是msdn里面的代码,待会我传我自己的吧,我都在搞这个东西呢
      

  2.   


    if (e.RowIndex > -1 && e.ColumnIndex > -1)
    {
        MousePosition.X
        MousePosition.Y
       //此时X,Y在单元格范围之内
    }
      

  3.   


    补充:是在_CellMouseEnter事件里面
      

  4.   


    string str = this.dataGridView1.CurrentCell.Value.ToString();//獲取選中單元格的值
    string strHeaderTest = this.dataGridView1.Columns[1].HeaderCell.Value.ToString();//獲取選中列的表頭
      

  5.   

    我在datagridview1中附加了datagridview2  就是想让 datagridview1 添加一行时, datagridview2 获取坐标 紧跟这移动。
      

  6.   


    private void DataGridview1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
            {
                string value = "";
                if (e.RowIndex > -1 && e.ColumnIndex > -1)
                {
                    //取得当前单元格的值
                    value = grd.grd.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                    //获取单元格的坐标
                    int i = MousePosition.X;
                    int j = MousePosition.Y;
                }
            }
      

  7.   


    int num1=this.dataGridView1.CurrentCell.ColumnIndex;//獲取當前單元格列的索引值
    int num2 = this.dataGridView1.CurrentCell.RowIndex;//獲取當前單元格行的索引值你自己组合吧,哈哈……
      

  8.   

    使用如下方法:DataGridView.GetCellDisplayRectangle 方法public Rectangle GetCellDisplayRectangle (
    int columnIndex,
    int rowIndex,
    bool cutOverflow
    )
      

  9.   

    Rectangle _CellRectangle = dataGridView1.GetCellDisplayRectangle(0, 0, true);