好吧,在弄乱你的代码一段时间后,我一直被难住了。后来我终于意识到了这个问题。我假设 _dtRow 是一个 DataRow。您需要引用实际的数据表(dt)。
this.textBox1.DataBindings.Add("Text", dt, "Name");
编辑:看到您对伊戈尔帖子的评论后。如果您绑定到 dt,那么例如,如果您有一个绑定到此 DataTable 的 datagridview,则每次您选择不同的行时,文本框都会更改。
这是适合我的代码:
DataTable dt = new DataTable("Woot");
dt.Columns.AddRange(new DataColumn[]{
new DataColumn("ID",typeof(System.Guid)),
new DataColumn("Name",typeof(String))
});
dt.Rows.Add(Guid.NewGuid(), "John");
dt.Rows.Add(Guid.NewGuid(), "Jack");
this.dataGridView1.DataSource = dt;
this.textBox1.DataBindings.Add("Text", dt, "Name");
更改 DGV 中的行,您将看到文本框更改文本。
再次开斋节好的,是时候破解它了。这就是我让它工作的方式:
this.textBox1.DataBindings.Add("Text",_dtRow.ItemArray[1], "");
我使用了索引 1,但您可以使用数组中所需的任何索引。