944,162 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 8090
  • VB.NET RSS
Dec 13th, 2005
0

Combo box selection problem

Expand Post »
Hi,

I have a problem when selecting values from some combo boxes.

I have a form with two combo boxes next to each other, they both have the same data source, which is an array. I need to be able to select different values in each combo box.

My problem is that when the user selects a value from either combo box, it sets the other combo box to the same value. So the values in the combo boxes are always the same as each other, I can't make one different from the other unless I type in one of them.

I don't have any events coded for these combo boxes, so it seems to be something with .NET.

I've tried moving the combo boxes away from each other, putting then on different panels and group boxes and nothing has worked.

Any help would be appreciated

Thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hippychic43 is offline Offline
14 posts
since Mar 2005
Dec 13th, 2005
0

Re: Combo box selection problem

The only way I've found around this problem, is to create two arrays, one for each combo box, that store the same stuff. This is what my code that doesn't work looks like:

Quote ...
Dim dose() As String = {"1/2", "1", "1 & 1/2", "2", "2 & 1/2", "3", "4", "5", "6", "1/2 ml", "1 & 1/2 ml", "2 ml", "2 & 1/2 ml", "3 ml", "4 ml", "5 ml", "10 ml", "15 ml"}
cboMedDose.DataSource = dose
cboPatDose.DataSource = dose
This is the code that works where I create another array:

Quote ...
Dim dose() As String = {"1/2", "1", "1 & 1/2", "2", "2 & 1/2", "3", "4", "5", "6", "1/2 ml", "1 & 1/2 ml", "2 ml", "2 & 1/2 ml", "3 ml", "4 ml", "5 ml", "10 ml", "15 ml"}
cboMedDose.DataSource = dose
Dim somethingElse() As String = {"1/2", "1", "1 & 1/2", "2", "2 & 1/2", "3", "4", "5", "6", "1/2 ml", "1 & 1/2 ml", "2 ml", "2 & 1/2 ml", "3 ml", "4 ml", "5 ml", "10 ml", "15 ml"}
cboPatDose.DataSource = somethingElse
I tried this as well, and it didn't work:

Quote ...
Dim dose() As String = {"1/2", "1", "1 & 1/2", "2", "2 & 1/2", "3", "4", "5", "6", "1/2 ml", "1 & 1/2 ml", "2 ml", "2 & 1/2 ml", "3 ml", "4 ml", "5 ml", "10 ml", "15 ml"}
cboMedDose.DataSource = dose
Dim somethingElse() As String = dose
cboPatDose.DataSource = somethingElse
If anyone could think of a better solution I'd really appreciate it.

Thanks
Cristy
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hippychic43 is offline Offline
14 posts
since Mar 2005
Jun 9th, 2006
0

Re: Combo box selection problem

Dim SomethingElse() as String = dose

doesn't work because both variables still reference the same array instance. Use the array's Clone method to create the second copy for you.

Dim dose() As String = {"1/2", "1", "1 & 1/2", "2", "2 & 1/2", "3", "4", "5", "6", "1/2 ml", "1 & 1/2 ml", "2 ml", "2 & 1/2 ml", "3 ml", "4 ml", "5 ml", "10 ml", "15 ml"}
Dim SomethingElse() as String = dose.Clone

cboMedDose.DataSource = dose
cboPatDose.DataSource = SomethingElse

Quote originally posted by hippychic43 ...
The only way I've found around this problem, is to create two arrays, one for each combo box, that store the same stuff. This is what my code that doesn't work looks like:



This is the code that works where I create another array:



I tried this as well, and it didn't work:



If anyone could think of a better solution I'd really appreciate it.

Thanks
Cristy
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JCinSB is offline Offline
1 posts
since Jun 2006
Jun 10th, 2006
0

Re: Combo box selection problem

I always feel shorter is better so just add .clone onto your dose
VB.NET Syntax (Toggle Plain Text)
  1. Dim dose() As String = {"1/2", "1", "1 & 1/2", "2", "2 & 1/2", "3", "4", "5", "6", "1/2 ml", "1 & 1/2 ml", "2 ml", "2 & 1/2 ml", "3 ml", "4 ml", "5 ml", "10 ml", "15 ml"}
  2. cboMedDose.DataSource = dose.Clone
  3. cboPatDose.DataSource = dose.Clone
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002
Oct 31st, 2006
0

Re: Combo box selection problem

I always feel shorter is better so just add .clone onto your dose
VB.NET Syntax (Toggle Plain Text)
  1. Dim dose() As String = {"1/2", "1", "1 & 1/2", "2", "2 & 1/2", "3", "4", "5", "6", "1/2 ml", "1 & 1/2 ml", "2 ml", "2 & 1/2 ml", "3 ml", "4 ml", "5 ml", "10 ml", "15 ml"}
  2. cboMedDose.DataSource = dose.Clone
  3. cboPatDose.DataSource = dose.Clone
Try disabling databinding on the dose object
eg
Me.BindingContext.Item(dose).SuspendBinding()

where Me is the form. This lets you use the one source for your combo box. Ofcourse you will need to manually make any changes in response the SelectedValue/ Index chnage events on the combo boxes
Reputation Points: 10
Solved Threads: 0
Newbie Poster
outside404 is offline Offline
1 posts
since Oct 2006
Oct 31st, 2006
0

Re: Combo box selection problem

never mind.
Last edited by waynespangler; Oct 31st, 2006 at 10:41 pm.
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Dataset to Listbox for selection by user
Next Thread in VB.NET Forum Timeline: Audio Conversion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC