1 Attachment(s)
[RESOLVED] Th information in a ComboBox and reference to a database???
I have a problem getting the right information to a ComboBox.
I have a table in SQL Server that contains a list of names.
I want to get those names to appear in my ComboBoxes shown in the picture. (DONE)
I also want the list of names to decrease by the names already used in other ComboBoxes in that Form...
EXAMPLE:
So, lets say I have a list:
Name_1
Name_2
Name_3
Name_4
Name_5
Name_6
In the Form, there are 10 ComboBoxes.
I choose the Name_1 for ComboBox1, Name_2 for ComboBox2 and Name_3 for ComboBox3.
The options available for all other ComboBoxes should be Name_4 ... Name_6.
If all of the 6 names are filled, the rest of the ComboBoxes should have no option to insert into them...
Re: Th information in a ComboBox and reference to a database???
:wave:
The way I would approach it would be to just populate the first combobox with the values from the table.
Then, after the user selects the value for combobox1, go back to the database and extract all values from the table except the one just selected, and put those values in combobox2.
When the user selects a value from combobox2, then populate combobox3 with all the values from the database minus the two selected.
You can continue this pattern on down the line.
You may also want to make sure all the comboboxes below the one you populate have their item lists cleared. That way, if a user is on the 5th combobox and decides to jump back to the second one and make a selections, then the 4th and 5 boxes will have their selections cleared.
This is assuming that the user needs to follow a top-down progression on the list. If the user can jump from any combobox to another, then it would have to be handled differently.
Re: Th information in a ComboBox and reference to a database???
Quote:
Originally Posted by
dolot
:wave:
The way I would approach it would be to just populate the first combobox with the values from the table.
Then, after the user selects the value for combobox1, go back to the database and extract all values from the table except the one just selected, and put those values in combobox2.
When the user selects a value from combobox2, then populate combobox3 with all the values from the database minus the two selected.
You can continue this pattern on down the line.
You may also want to make sure all the comboboxes below the one you populate have their item lists cleared. That way, if a user is on the 5th combobox and decides to jump back to the second one and make a selections, then the 4th and 5 boxes will have their selections cleared.
This is assuming that the user needs to follow a top-down progression on the list. If the user can jump from any combobox to another, then it would have to be handled differently.
I tried to do this, but got an error every way i tried...
I made a new TableAdapter in which I populated the info from the database MINUS the information chosen in the ComboBox above... So basically the query was the same as for the Box above, but I added a requirement for the where clause...
Code:
WHERE ........... dbo.List.NameColumn <> @NameInBox1
Then when populating the info in VB, the code recuires me to assign the @NameInBox1.....
Code:
NameInox1:=ComboBox1.Text
That way seemed very logical to me, but I get an error:
"Object reference not set to an instance of an object."
Re: Th information in a ComboBox and reference to a database???
Quote:
Originally Posted by
Hamsori
That way seemed very logical to me, but I get an error:
"Object reference not set to an instance of an object."
That means that one of the variables or properties you're accessing is set to nothing. Once you determine which one it is you can better address the problem. My suspect is the 'Text' property of combobox1, but I can't say for sure.
Re: Th information in a ComboBox and reference to a database???
say you have selected Name_1 in combobox1, then for the remaining cmbxs just do a FindStringExact and remove the item by using the Index returned the FindStringExact function
But, this method is not feasible is the selected value in any of the combobox is changed