Results 1 to 5 of 5

Thread: [RESOLVED] Th information in a ComboBox and reference to a database???

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    110

    Resolved [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...
    Attached Images Attached Images  

  2. #2
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: Th information in a ComboBox and reference to a database???


    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 always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    110

    Re: Th information in a ComboBox and reference to a database???

    Quote Originally Posted by dolot View Post

    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."

  4. #4
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: Th information in a ComboBox and reference to a database???

    Quote Originally Posted by Hamsori View Post
    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.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  5. #5
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width