Binding a TextBox to a DataGrid

P

Peder Y

How do I bind a TextBox to a DataGrid? If I bind it to the DataGrid
DataTable, the TextBox doesn't get updated when I select another row. Do
I need to handle some DataGrid events?

- Peder -
 
P

Peder Y

It took some @£$½£$@£-work and swearing, but I finally found the
solution to my problem. For others with the same problems I repost what
I found. The following code is from another post and it proved useful:

http://groups.google.com/[email protected]&rnum=9

dataGrid1.DataSource = myCustomersDataset.Customers
dataGrid1.DataMember = ""
textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text",
myCustomersDataset.Customers, "CompanyName"))

dataGrid2.DataSource = myCustomersDataset
dataGrid2.DataMember = "Customers"
textBox2.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.myCustomersDataset, "Customers.CompanyName"))

Mixing these two versions of using the bindings results in (in my case)
the TextBox being bound to the first row of the grid and getting stuck
there unless the CurrencyManager.Position is updated manually. Very
frustrating, but I hope this might shed some light on the situation for
others that suffer the same problem as I.

Cheers!

- Peder -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top