本帖最后由 cacagege 于 2009-09-28 19:53:06 编辑

解决方案 »

  1.   

    dgv.DataSource = ds.Tables[0];txt.DataBindings.Add("Text", ds.Tables[0], "字段名");
      

  2.   

    简单的,不要写任何代码即可
    首先,为窗口增加一个BindingSource,然后为BindingSource设置数据源(即填充DataGridView用的数据源)
    然后设定DataGridView的数据源为该BindingSource.
    然后增加TextBox,设定TextBox的DataBindings中的Text属性为BindingSource中你想显示的列名。
    这样,就可以做到你选择DataGridView中不同行的时候,文本框的内容跟着发生变换。
      

  3.   

    你的意思是
    选中不同行txt内容变化成相应内容?
      

  4.   

     private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
     {
         DataGridView.HitTestInfo hit ;     if (e.Button == MouseButtons.Left)
         {
             hit = this.dataGridView1.HitTest(e.X, e.Y);
             this.textBox1.Text = ds.Tables[0].Columns[hit.ColumnIndex].ColumnName;
         }
     }
    利用DataGridView的HitTestInfo方法,抓取當前點擊的列。
      

  5.   

    用dataRelation或者就通过dataGridview的EntryRow事件手动赋值~~
      

  6.   

    CurrentCellChanged事件中手动赋值
      

  7.   

     this.textBox1.Text  = dataGridView1.CurrentRow.Cells[1].Value.ToString();
      

  8.   

    可以通过datagridview的事件来实现