datagridview中查询到的数据
点击datagridview中的一行数据,让数据中对应的项相应的在textbox 中显示。

解决方案 »

  1.   

    textbox.Text = datagridview.CurrentRow.Cells[0,0].Value.ToString();
    参考C# WinForm开发系列 - DataGridView
      

  2.   

    这个方法很多,按照楼主的意思最好在事件(endcell事件)里面做比较好,通过datagridview.CurrentRow.Cells[n1,n2].Value.ToString(); 来获得需要的数据datagridview有个
      

  3.   

    cellend事件代码参考
    //       datagridview单元格值发生变化的时候出发这个事件             
      private   void   datagridview_CellEndEdit(object   sender,   DataGridViewCellEventArgs   e)   
                      {   
                              string   strSelecteddgrd;   
                              string   strtype;   
        
                              //选中的那行   
                              int   intInputRow   =   this.datagridview.CurrentCell.RowIndex;   
        
                              //选中的那行单元格id记录   
                              strSelecteddgrd   =   this.datagridview.Rows[intInputRow].Cells[2].Value.ToString();   
                                
                              //选中的那行属性类型   
                              strtype   =   this.datagridview.Rows[intInputRow].Cells[3].Value.ToString();   
                              //如果验证出错   
                              if   (!InputCheck(strSelecteddgrd,   strtype))   
                              {   
                                    //焦点返回到修改时候的单元格   
                                      datagridview.Rows[intInputRow].Cells["Param_Value"].Selected   =   true;   
                                      return;   
                              }   
                      }   
      

  4.   

    楼上的有没搞错呀!是点击的时候耶!应该是在_CellClick事件里面写才是呀!
      

  5.   

    dataGrindView的SelectionMode属性改为FullRowSelected
    再用click事件
    例如:
    txtName.Text = dataGridView1.SelectedCells[0].Value.ToString();
                txtCardNUm.Text = dataGridView1.SelectedCells[1].Value.ToString();
                txtNum.Text = dataGridView1.SelectedCells[2].Value.ToString();
                txtSex.Text = dataGridView1.SelectedCells[3].Value.ToString();
                txtAge.Text=dataGridView1.SelectedCells[4].Value.ToString();
                txtTel.Text = dataGridView1.SelectedCells[5].Value.ToString();
      

  6.   

    取到gridview所绑定的dataset/datatable,经过转换取到相应的实体类,把textbox的field属性设置为entity的属性,利用反射foreach (PropertyInfo pInfo in entity.GetType().GetProperties())
                {
                    foreach (IInputControl c in view.InputControls)
                    {
                        if (string.Equals(pInfo.Name,c.Field,StringComparison.OrdinalIgnoreCase))
                            c.Value = pInfo.GetValue(entity,null);
                    }
                }
      

  7.   

    可以在formload中就给相应的textbox赋值了
      

  8.   

    1, 定义一个全局变量 private int currentrow; //选中行索引  //dataGrindView单元格单击事件
    2,private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
       {
            //获得当前行索引
            this.currentrow = this.dgv.CurrentCell.RowIndex;
        
        this.TextBox1.Text = this.dgv.Rows[currentrow].Cells[1].Value;
       }
      

  9.   

    绑定到同一个数据源就是了。DataGridView中当前记录变化,相应的TextBox中的内容会自动变化。