DataGridView的问题 本帖最后由 cacagege 于 2009-09-28 19:53:06 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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(); 可以通过datagridview的事件来实现 listbox的显示问题 紧急求助:c的dll函数转为c#.net,解决后马上100分。谢谢。 C# 问个小白的问题 重新发贴DataGrid的问题。 请教怎样做对象深拷贝? 如何再.net中生成dll文件 C# ^_^ 高手来这里看看 ^_^ 有关Session的问题 请问:在WindowsApplication中如何获得当前DataGrid中选中的行的信息? 请推荐ASP.NET实战提高的书 《有关数据库存表的问题》
首先,为窗口增加一个BindingSource,然后为BindingSource设置数据源(即填充DataGridView用的数据源)
然后设定DataGridView的数据源为该BindingSource.
然后增加TextBox,设定TextBox的DataBindings中的Text属性为BindingSource中你想显示的列名。
这样,就可以做到你选择DataGridView中不同行的时候,文本框的内容跟着发生变换。
选中不同行txt内容变化成相应内容?
{
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方法,抓取當前點擊的列。