当前位置:编程学习 > C#/ASP.NET >>

DataGridView的问题

--------------------编程问答-------------------- dgv.DataSource = ds.Tables[0];

txt.DataBindings.Add("Text", ds.Tables[0], "字段名"); --------------------编程问答-------------------- 简单的,不要写任何代码即可
首先,为窗口增加一个BindingSource,然后为BindingSource设置数据源(即填充DataGridView用的数据源)
然后设定DataGridView的数据源为该BindingSource.
然后增加TextBox,设定TextBox的DataBindings中的Text属性为BindingSource中你想显示的列名。
这样,就可以做到你选择DataGridView中不同行的时候,文本框的内容跟着发生变换。
--------------------编程问答-------------------- 你的意思是
选中不同行

txt内容变化成相应内容? --------------------编程问答-------------------- 帮顶先 等高人来 --------------------编程问答--------------------  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方法,抓取當前點擊的列。 --------------------编程问答-------------------- 用dataRelation或者就通过dataGridview的EntryRow事件手动赋值~~ --------------------编程问答-------------------- CurrentCellChanged事件中手动赋值 --------------------编程问答--------------------  this.textBox1.Text  = dataGridView1.CurrentRow.Cells[1].Value.ToString(); --------------------编程问答-------------------- up --------------------编程问答-------------------- BindingSource设置数据源 --------------------编程问答-------------------- up --------------------编程问答-------------------- 可以通过datagridview的事件来实现
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,