在一个DataGrid中显示了一个表的三列数据
我想在点DataGrid时候,自动把在DataGrid上所选的一行填到三个文本框里
谁能帮我写一段代码实现,谢谢了!

解决方案 »

  1.   

    e.Items[i].Cells[2].Text().ToString(),
      

  2.   

    textBox1.text=e.Item.Cells[0].Text.ToString();
    textBox2.text=e.Item.Cells[1].Text.ToString();Cells[0]是第一个单元格
    Cells[1]是第二个单元格
      

  3.   

    WinForm:textBox1.text=datagrig[i, 0];
    textBox2.text=datagrig[i, 1];
    textBox3.text=datagrig[i, 2];
      

  4.   

    这段代码具体是怎么用的?能不能写详细些?textBox1.text=datagrig[i, 0];
    textBox2.text=datagrig[i, 1];
    textBox3.text=datagrig[i, 2];
      

  5.   

    你可以自己给datagrid加个编辑按纽,响应这个编辑按纽的事件就行了,在里边写上边的代码。
      

  6.   

    我做的应用程序,dataGrid中没法加编辑按钮
      

  7.   

    可以写在DataGridCellChange事件里吧
      

  8.   

    应用程序中的DataGrid中就没有DataGridCellChange, 这个事件
      

  9.   

    this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);//在窗体初始化时把这个触发事件写上,否则不会执行,这也是为什么那么多人问没有触发的原因!//当dataGrid1中选中的行变化时,触发该函数.
    private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e) 
    {
    //清空当前zsmx的信息
    this.dataSet11.Tables["zsmx"].Clear();
    //根据clch查询得到dataGrid2要显示的值
    string s1=(string)this.dataSet11.Tables["zslc"].Rows[this.dataGrid1.CurrentRowIndex][4];
    this.sqlSelectCommand2.Parameters["@clch"].Value=s1;
    this.sqlDataAdapter2.Fill(this.dataSet11);
    //重新绑定dataGrid2,这样才能适时更新
    this.dataGrid2.SetDataBinding(this.dataSet11,"zsmx");
    }
      

  10.   

    以上是选中dataGrid1中的一行,根据选中这一行的某列数据查询相关内容,显示在dataGrid2中。显示在文本框中,只要取得选中这一行的数据即可:string s1=(string)this.dataSet11.Tables["zslc"].Rows[this.dataGrid1.CurrentRowIndex][n];//n表示是选中那行的某列,
      

  11.   

    我试了你这个办法了,可是要是写在这个事件里,第一次点dataGird的时候不能显示
    只有在第二次点的时候才能可以,不过真谢谢你!
      

  12.   

    看例子:::public void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
    {
         //更新数据库中的信息
        string strName = e.ItemCells[1].Text;
        int intChines = Int32.Parse(((TextBox)e.Item.Cells[2].Controls[0].Text)); //e.Item.Cells[3].Controls[0]表示的是当前激发事件表格行的第三个单元格的第一个控件.在DataGrid的编辑应用中这个控件是TextBox
        int intMath = Int32.Parse(((TextBox)e.Item.Cells[3].Controls[0]).Text);
        int intEnglist = Int32.Parse(((TextBox)e.Item.Cells[4].Controls[0]).Text);
        //更新数据库中的数据
        string strUpdate = "Update Score Set Chinese=" + intChinese + ",Math="+intMath + ",English= "intEnglish + "Where Name ="
        '"+strName+"'";
        OleDbCommand MyComm = new OleDbCommand(strUpdate,MyConn);
        MyComm.ExecuteNonQuery();
        score.EditItemIndex = -1;
        BindGrid();   //重新绑定DataGrid控件
    }
      

  13.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=8ADE535F-AD40-4DE3-A962-A64B4FAF12C4
      

  14.   

    private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
       DataGrid dg = (DataGrid)sender;
       DataGridCell myCell = dg.CurrentCell;
       MessageBox.Show(myCell.ToString());
    }