我用textbox绑定数据,this.textbox1.DataBindings.Add("Text", dt, "职员编号");现在就是用datagridview时,我选中datagridview中的任务何一行的职员编号。
textbox1还只是显示第一行的数据。如何让textbox1,绑定到我选择任何一行的数据。。(请高手们多多指点)

解决方案 »

  1.   

    Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
            Dim i As Int16
            For i = 0 To DataGridView1.ColumnCount - 1
                textbox1.text &= DataGridView1.Item(i, e.RowIndex)
            Next
        End Sub
      

  2.   

    谢谢楼上的不过我是想要绑定数据库,textbox1,绑定到我选择任何一行的数据
      

  3.   

    考虑下都绑定到BindingSource组件
      

  4.   

    BingdingSource bs = new BindingSource();
    bs.DataSoruce = dt;
    textBox1.DataBindings.Add("Text", bs, "职员编号");
    dataGridView1.DataSource = bs;
      

  5.   

    c/s的做法<a herf='dizhi?id=<%# bind("字段") %>'下个也面读取 发来的
      

  6.   

    this.textbox1.DataBindings.Add("Text", dt.Talbe[0].Rows[e.RowIndex], "职员编号");
      

  7.   

    你的DataGridView是怎么绑定的数据库?贴出相关代码来看看...
      

  8.   

    给你写个小例子:private void DataBind()
            {
                SqlConnection con = new SqlConnection("server=.;database=student;uid=sa;pwd=0421");
                SqlDataAdapter sda = new SqlDataAdapter("select * from studentDetails", con);
                sda.Fill(ds, "student");
                //数据绑定
                this.dataGridView1.DataSource = ds.Tables["student"];
                this.textBox1.DataBindings.Add("Text", ds.Tables["student"], "sno");
                this.textBox2.DataBindings.Add("Text", ds.Tables["student"], "sname");
                this.textBox3.DataBindings.Add("Text", ds.Tables["student"], "sage");
            }
      

  9.   

    谢谢楼上的。你的方法和我的差不多。你使用了DATASET 我用DATATABLE 方法都是一样的。也就只能绑定第一条的记录。我还是实现不了。让textbox1,绑定到我选择任何一行的数据。。
      

  10.   

    TO:也就只能绑定第一条的记录。我还是实现不了。让textbox1,绑定到我选择任何一行的数据。。最初显示的是第一条记录,并不是说只绑定了第一条记录,你不是还绑定了DataGridView了吗?你选中DataGridView的不同项,TextBox中的值也会随着变化的...
      

  11.   

    我选中DATAGRIDVIEW 的不同项,TEXTBOX中的值没有变。。还是DATAGRIDVIEW的第一条记录的值。
      

  12.   

    private void Form1_Load(object sender, EventArgs e)
            {
                dataGridView1.AllowUserToAddRows = false;
                da = new SqlDataAdapter("SELECT * FROM 职员基本信息表", conn);
                da.Fill(dtable);
                bindingSource1.DataSource = dtable;
                dataGridView1.DataSource = bindingSource1;
                DataBindingsFunction();
            }
            private void DataBindingsFunction()
            {
                this.textBox1.DataBindings.Add("Text", btable, "职员编号");
                this.textBox2.DataBindings.Add("Text", btable, "姓名");
                .......
            }
      

  13.   

    try........
    this.textBox1.DataBindings.Add("Text", bindingSource1, "职员编号");
    this.textBox2.DataBindings.Add("Text", bindingSource1, "姓名");
    ......
      

  14.   

    楼上的谢谢了OK了。。呵你QQ多少。。交流交流。
      

  15.   

    绑定视图看看呢?
    this.textbox1.DataBindings.Add("Text", dt.DefaultView, "职员编号");