|
-
Sep 28th, 2006, 06:04 AM
#1
Thread Starter
Lively Member
[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.
-
Sep 28th, 2006, 06:10 AM
#2
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
-
Sep 28th, 2006, 06:11 AM
#3
Re: Combo Box Issue
 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."
-
Sep 28th, 2006, 06:11 AM
#4
Re: Combo Box Issue
 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
-
Sep 28th, 2006, 06:29 AM
#5
Re: Combo Box Issue
VB Code:
Private Sub cmbdestination_Click()
If cmbdestination.Text = cmbsource.Text Then
MsgBox "Sorry, the destimation can not be the same as the source"
cmbdestination.ListIndex = -1
End If
End Sub
-
Sep 28th, 2006, 07:06 AM
#6
Thread Starter
Lively Member
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?.
-
Sep 28th, 2006, 07:10 AM
#7
Thread Starter
Lively Member
Re: Combo Box Issue
Mark,
How do i dynamically load a combo box???
Got any links that can help me?
Thanx
-
Sep 28th, 2006, 07:19 AM
#8
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?
-
Sep 28th, 2006, 07:27 AM
#9
Thread Starter
Lively Member
Re: Combo Box Issue
Hack,
I use only one table to load both the combo
-
Sep 28th, 2006, 07:32 AM
#10
Addicted Member
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.
-
Sep 28th, 2006, 07:39 AM
#11
Re: Combo Box Issue
HOw about something like this
VB Code:
Private Sub ComboBox1_Click()
ComboBox2.List = ComboBox1.List
ComboBox2.RemoveItem ComboBox1.ListIndex
End Sub
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Sep 28th, 2006, 11:16 PM
#12
Thread Starter
Lively Member
Re: Combo Box Issue
Thank You Shuja Ali,
I will try your code and inform you of the result.
-
Sep 28th, 2006, 11:38 PM
#13
Thread Starter
Lively Member
Re: Combo Box Issue
The code required some modification so wrote the following code.
VB Code:
Private Sub CmbSource_Click()
CmbDestination = CmbSource
CmbDestination.RemoveItem Cmbsource.ListIndex
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?
-
Sep 28th, 2006, 11:43 PM
#14
Re: Combo Box Issue
This code:
VB Code:
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
-
Sep 29th, 2006, 12:55 AM
#15
Thread Starter
Lively Member
Re: Combo Box Issue
You are Right Chemical Nova,
I did correct the code to
VB Code:
CmbDestination.List = CmbSource.List
But now i get a error saying 'Arguement not optional'
-
Sep 29th, 2006, 01:00 AM
#16
Re: Combo Box Issue
You have to manually add them beforehand:
VB Code:
Dim i As Integer
For i = 0 To Combo1.ListCount - 1
Combo2.AddItem Combo1.List(i)
Next i
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 29th, 2006, 01:14 AM
#17
Thread Starter
Lively Member
Re: Combo Box Issue
Ok Chem,
Will try it and thank you
-
Sep 29th, 2006, 01:57 AM
#18
Thread Starter
Lively Member
Re: Combo Box Issue
Chem,
I did write the following code
VB Code:
Private Sub CmbSource_Click()
Dim i as integer
For i = 0 to CmbSource.ListCount - 1
CmbDestination.AddItem CmbSource.list(i)
Next i
CmbDestination.RemoveItem CmbSource.ListIndex
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!!!
-
Sep 29th, 2006, 02:49 AM
#19
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:
Private Sub cmbSource_Click()
Dim i As Integer
cmbDestination.Clear 'added this line
For i = 0 To cmbSource.ListCount - 1
cmbDestination.AddItem cmbSource.List(i)
Next i
cmbDestination.RemoveItem cmbSource.ListIndex
End Sub
-
Sep 29th, 2006, 04:11 AM
#20
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|