Results 1 to 20 of 20

Thread: [Finally Resolved]Combo Box Issue

  1. #1

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Exclamation [Finally Resolved]Combo Box Issue

    I have 2 combo box(cmbsource, cmbdestination) with names of cities in the list,

    Goods transfer happen from Source(cmbsource) to Destination(cmbdestination)

    Now what i need to know is how to stop the user from picking up the same city in source and destination?
    Last edited by vasanth2979; Sep 29th, 2006 at 04:12 AM.

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Combo Box Issue

    If the data present is same in both the comboboxes and both of them are sorted, then you can use ListIndex property of the combobox to check if the user has selected the same city in both the comboboxes.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Combo Box Issue

    Quote Originally Posted by vasanth2979
    I have 2 combo box(cmbsource, cmbdestination) with names of cities in the list,

    Goods transfer happen from Source(cmbsource) to Destination(cmbdestination)

    Now what i need to know is how to stop the user from picking up the same city in source and destination?
    Why not dynamically load the second Combobox after the user selects the Source City and omitting the selected city from the second combobox when it is loaded.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: Combo Box Issue

    Quote Originally Posted by vasanth2979
    I have 2 combo box(cmbsource, cmbdestination) with names of cities in the list,

    Goods transfer happen from Source(cmbsource) to Destination(cmbdestination)

    Now what i need to know is how to stop the user from picking up the same city in source and destination?
    For this you have to check the conbo box fro the data... if it is found the you can use your condition... you can use the ListCount Property for it

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Combo Box Issue

    VB Code:
    1. Private Sub cmbdestination_Click()
    2.  
    3.     If cmbdestination.Text = cmbsource.Text Then
    4.         MsgBox "Sorry, the destimation can not be the same as the source"
    5.         cmbdestination.ListIndex = -1
    6.     End If
    7.    
    8. End Sub

  6. #6

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Re: Combo Box Issue

    Guys,

    I have done the same code what Martinliss has given me.What Im asking is, Is there any way i can make the city selected in combo1 not appear in combo2?.

  7. #7

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Re: Combo Box Issue

    Mark,

    How do i dynamically load a combo box???

    Got any links that can help me?


    Thanx

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Combo Box Issue

    If the cities are stored in database tables (source table - destination table) then you would need to create a "link" between the two tables which would match source with destination. Some like a destination code.

    When a person selects a source, you would query the destination table and load the other combo with cities that match the source cities destination code.

    Make sense?

  9. #9

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Re: Combo Box Issue

    Hack,

    I use only one table to load both the combo

  10. #10
    Addicted Member
    Join Date
    Jun 2006
    Posts
    136

    Re: Combo Box Issue

    In the first combo box's click event you can list out the items of second one.While listing out the second combo box's list just skip the selected item of first combo.

  11. #11
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Combo Box Issue

    HOw about something like this
    VB Code:
    1. Private Sub ComboBox1_Click()
    2.     ComboBox2.List = ComboBox1.List
    3.     ComboBox2.RemoveItem ComboBox1.ListIndex
    4. End Sub
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  12. #12

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Re: Combo Box Issue

    Thank You Shuja Ali,

    I will try your code and inform you of the result.

  13. #13

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Angry Re: Combo Box Issue

    The code required some modification so wrote the following code.
    VB Code:
    1. Private Sub CmbSource_Click()
    2.    CmbDestination = CmbSource
    3.    CmbDestination.RemoveItem Cmbsource.ListIndex
    4. End Sub

    This code works fine if the first item is selected in Combo1(It is removed from Combo2) but if i select any other item "Invalid Procedure call or arguement" Error is generated.

    What may be the Reason?

  14. #14
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Combo Box Issue

    This code:
    VB Code:
    1. CmbDestination = CmbSource
    Will not add the contents of the first combobox. When you try and remove anything greater than the first index, this error occurs, because there isn't more than 1 item in the CmbDestination Combobox.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  15. #15

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Re: Combo Box Issue

    You are Right Chemical Nova,

    I did correct the code to
    VB Code:
    1. CmbDestination.List = CmbSource.List
    But now i get a error saying 'Arguement not optional'

  16. #16
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Combo Box Issue

    You have to manually add them beforehand:
    VB Code:
    1. Dim i As Integer
    2. For i = 0 To Combo1.ListCount - 1
    3. Combo2.AddItem Combo1.List(i)
    4. Next i
    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  17. #17

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Re: Combo Box Issue

    Ok Chem,

    Will try it and thank you

  18. #18

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Re: Combo Box Issue

    Chem,

    I did write the following code
    VB Code:
    1. Private Sub CmbSource_Click()
    2. Dim i as integer
    3.  For i = 0 to CmbSource.ListCount - 1
    4.     CmbDestination.AddItem CmbSource.list(i)
    5.  Next i
    6. CmbDestination.RemoveItem CmbSource.ListIndex
    7. End Sub


    Combo Box 2 doesnot have Combo1 value but the other values repeat themselves twice!! Any Clue what is happening?

    Im stuck with this problem for last two days!!!

  19. #19
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Combo Box Issue

    Actually, the values only repeat themselves if you select an item from cmbSource, and then select another after that. Simple fix, clear the second ComboBox before copying the stuff over.
    VB Code:
    1. Private Sub cmbSource_Click()
    2.   Dim i As Integer
    3.   cmbDestination.Clear  'added this line
    4.   For i = 0 To cmbSource.ListCount - 1
    5.     cmbDestination.AddItem cmbSource.List(i)
    6.   Next i
    7.   cmbDestination.RemoveItem cmbSource.ListIndex
    8. End Sub
    Like Archer? Check out some Sterling Archer quotes.

  20. #20

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Resolved Re: Combo Box Issue

    Thank you Kows, It worked finally

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