用下列方法引用表格中的单元格.
datagrid[datagrid.CurrentRowIndex,0];
datagrid[datagrid.CurrentRowIndex,1];
datagrid[datagrid.CurrentRowIndex,2];

解决方案 »

  1.   

    DataGrid myGrid = (DataGrid) sender;
    System.Windows.Forms.DataGrid.HitTestInfo hti;
    hti = myGrid.HitTest(e.X, e.Y);
                
    if(hti.Type == System.Windows.Forms.DataGrid.HitTestType.Cell || hti.Type==System.Windows.Forms.DataGrid.HitTestType.RowHeader)
    {//判断点击的类型,是否为单元格,此例中我选择获取开始的三个单元格的内容,根据hti.row的值确定单击的行
    myGrid.CurrentCell = new DataGridCell(hti.Row,0);
    textBox1.Text = dataGrid1[dataGrid1.CurrentCell].ToString();
    myGrid.CurrentCell = new DataGridCell(hti.Row,1);
    textBox2.Text = dataGrid1[dataGrid1.CurrentCell].ToString();
    myGrid.CurrentCell = new DataGridCell(hti.Row,2);
    textBox3.Text = dataGrid1[dataGrid1.CurrentCell].ToString();
    }