data binding combo boxes

chowchow123

Active member
Joined
Sep 6, 2007
Messages
34
Programming Experience
1-3
Hi

I have a series of combo boxes that are bound to the same table - and I would like each combobox to function independently. At the moment when I select something in one combobox all the others change to the same choice. Any ideas?
Thanks
 
Last edited:
Hi

Thanks for the reply. If I have a separate table for each combobox - each with the same set of choices isn't that reptitive data? Below is the code -

Me.Payment_typeComboBox4 = New System.Windows.Forms.ComboBox
Me.PaymentTypeBindingSource = New System.Windows.Forms.BindingSource(Me.components)
Me.Payment_typeComboBox3 = New System.Windows.Forms.ComboBox
Me.Payment_typeComboBox2 = New System.Windows.Forms.ComboBox
Me.Payment_typeComboBox1 = New System.Windows.Forms.ComboBox
 
If your main table required:

Customer1
Customer2
Customer3
Customer4

and you had 1 table in your database that stored all your customer details, you would require 4 "lookup" customer dataTables in your app, with a combobox bound to each dataTable.

Another example is one table in your DB storing all employee details.

EmployeeID | EmployeeName | EmployeeTypeID

1-------------John Doe--------1
2-------------John Smith-------2
3-------------Sarah Smith------2
4-------------Peter Parker------1

Where EmployeeID 1 = Manager and EmployeeID 2 = Supervisor

If your app needed to store the manager and a supervisor for a record, you wouldn't have an Employee DataTable. You would have a Manager DataTable and a SuperVisor DataTable (i.e. SELECT * FROM Employee WHERE EmployeeTypeID = 2)


In theory, you shouldn't require more than one binding to a table. If you do then you need to look at your database design or have a seperate DataTable for every instance.
 
remember you're loading the dataTable with x amount of dataRows from your database. Anything you "bind" to that dataTable will all access the same dataRow.

You cannot bind multiple components to a single DataTable and expect to be able to select different values with each binding.
I.E. customer dataTable with a comboBox set so that dataSource = CustomerSource. DisplayMember = CustomerName, ValueMember = CustomerID
You then have textboxes on the form bound to CustomerSource as well (CustomerName, Address1, Address2 etc etc)

As you change the customer in the ComboBox, the textboxes all bind to the SAME row as that selected in the combo.
 
thanks for the reply - I'll phrase things a little better with an example

Question 1

Suppose I have two forms and I use Form 1 for editing data and Form 2 for viewing the data with the fields as follows:

Form 1
TitleCombobox - bound to title table
NameTextBox - bound to membership table
SurnameTextBox - bound to membership table
StreetTextBox - bound to membership table

Form2
TitleTextBox - bound to membership table
NameTextBox - bound to membership table
SurnameTextBox - bound to membership table
StreetTextBox - bound to membership table

How can I ensure that the data read from the title table in form 1 is saved to the Title membership table in form 2

Question 2

Suppose I want to add a search facility and I have a combobox that gives dropdown choices of the headertitle
e.g. Name, Surname, Street
and a textbox where I type in the data to match that particular column

e.g. If I choose Name in the combobox, in the textbox I type the name to search on.

How could I get the table column headings to display in the combobox - do I have to create a separate table for this?
 
thanks for the reply - I'll phrase things a little better with an example

Question 1

Suppose I have two forms and I use Form 1 for editing data and Form 2 for viewing the data with the fields as follows:

Form 1
TitleCombobox - bound to title table
NameTextBox - bound to membership table
SurnameTextBox - bound to membership table
StreetTextBox - bound to membership table

Form2
TitleTextBox - bound to membership table
NameTextBox - bound to membership table
SurnameTextBox - bound to membership table
StreetTextBox - bound to membership table

How can I ensure that the data read from the title table in form 1 is saved to the Title membership table in form 2
Um, by not having 2 sources of data? If you want both your choir singers to sing them same song, have them read off the same sheet!


How could I get the table column headings to display in the combobox - do I have to create a separate table for this?
yes
 
Back
Top