在C#.net中,如何获取显示在DataGrid中,鼠标选中行,各字段的值?

解决方案 »

  1.   

    有一个DataGrid显示查询的结果.
    其中有几个TextBox控件用来显示,鼠标选中DataGrid行中的信息.
      

  2.   

    to 在C#.net中,如何获取显示在DataGrid中,鼠标选中行,各字段的值?你可以通过鼠标所点击获得数据源来获得DataRow,参看
    http://www.syncfusion.com/faq/windowsforms/search/934.aspx但是就你所说的,可以通过绑定来实现,例如:
    DataView dv = yourDataTable.DefaultView;
    yourDataGrid.DataSource = dv;
    yourTextBox.DataBindings.Add(new Binding
       ("Text", dv, "yourField"));
      

  3.   

    例如,DataGrid控件我已经绑定DataSet.Table[Student];在Student里的字段有NO,NAME,AGE
    下面有三个TEXTBOX控件,如何来显示鼠标选定DataGrid行中,对应字段的值?
      

  4.   

    dataGridView.Rows[curRow].Cells[column].Value = value
      

  5.   

    textbox .text=ds.tables[0].rows[curentrowindex][需要的字段].tostring();
      

  6.   

    Object[] rowRecordID=this.DataTable.DefaultView[this.dataGrid.CurrentCell.RowNumber].Row.ItemArray;
    int i=System.Convert.ToInt32(rowRecordID[0]);
    这个是在vs2003中可以使用的。