Question Databind question

gate7cy

Well-known member
Joined
May 11, 2009
Messages
119
Programming Experience
3-5
I am developing an application using visual studio 08 and mysql. In my form I have a datagridview control together with some databinded textboxes that reflect the information from the datagrid. So far all good. This was just a drag n drop from the data sources. The datagrid is binded to table 1 and so are the textboxes. In the same form I dragged some binded textboxes from table 2. The two tables are connected by the 'CustomerID' field. The textboxes from table 2 do not show the correct information according to the ID stored in table 1. How can do to show the correct values without using runtime queries and datareaders, etc. I want to avoid the runtime option because it presents new more compliated problems with my binding of the controls. I hope I was well understood. Thanks for the replies.
 
By default, when you just drag tables onto the form there is no specific relationship between the data. If you want the data in the child table to be filtered by the selection you make in the parent table then you need to adjust the data-bindings a bit. It can all be done in the designer so don't worry about having to write code.

By default, each BindingSource is bound to your DataSet with the appropriate DataTable selected as the DataMember. In order to facilitate automatic filtering, you need to bind the child BindingSource to the parent BindingSource instead, selecting the relationship as the DataMember. That way, when you select a parent record in the parent BindingSource, the child BindingSource will only expose children related to that parent.

By the way, the past tense of "bind" is "bound", not "binded".
 
Thanks for the reply. There is no child table. There are child textboxes that I cannot bind them to the bindingsource but only to a table. The child textboxes will diplay the data from their table according to the the selection made in the parent DataTable. This DataTable has a relationship with the table that the child textboxes are 'bound' to ( got it right now!!). So when I choose a record the child textboxes should show the correct data. I have tried to make a query in the Designer with a parameter to fill the data in the textboxes according to the connecting link, the CustomerID. This is stored as integer and shown in a textbox. I try to remove the integer from the textbox and use it as a parameter but I keep getting an error on trying to convert the text to integer, etc. Thanks for the reply. Here is what I have done. :

Dim xxx As Integer = Integer.Parse(CustomeridTextBox.Text)


Me.CustomerTableAdapter.customer(Me.Mysqldb.customer, xxx)

It does not work. If I assign the variable 'xxx' to an integer as so:
Dim xxx As Integer = 3
It works fine. When I try to get the number 3 from the textbox,no matter how I try to convert it, I get an error.. Any thoughts. Cheers
 

Latest posts

Back
Top