User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 402,622 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,211 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 5110 | Replies: 5
Reply
Join Date: Mar 2005
Posts: 14
Reputation: hippychic43 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
hippychic43 hippychic43 is offline Offline
Newbie Poster

Combo box selection problem

  #1  
Dec 13th, 2005
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2005
Posts: 14
Reputation: hippychic43 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
hippychic43 hippychic43 is offline Offline
Newbie Poster

Re: Combo box selection problem

  #2  
Dec 13th, 2005
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:

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:

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:

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
Reply With Quote  
Join Date: Jun 2006
Location: South Bend, IN
Posts: 1
Reputation: JCinSB is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
JCinSB JCinSB is offline Offline
Newbie Poster

Re: Combo box selection problem

  #3  
Jun 9th, 2006
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

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
Reply With Quote  
Join Date: Dec 2002
Location: West Virginia
Posts: 375
Reputation: waynespangler is on a distinguished road 
Rep Power: 6
Solved Threads: 37
waynespangler waynespangler is offline Offline
Posting Whiz

Re: Combo box selection problem

  #4  
Jun 10th, 2006
I always feel shorter is better so just add .clone onto your dose
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.Clone
cboPatDose.DataSource = dose.Clone 
Reply With Quote  
Join Date: Oct 2006
Posts: 1
Reputation: outside404 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
outside404 outside404 is offline Offline
Newbie Poster

Re: Combo box selection problem

  #5  
Oct 31st, 2006
Originally Posted by waynespangler View Post
I always feel shorter is better so just add .clone onto your dose
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.Clone
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
Reply With Quote  
Join Date: Dec 2002
Location: West Virginia
Posts: 375
Reputation: waynespangler is on a distinguished road 
Rep Power: 6
Solved Threads: 37
waynespangler waynespangler is offline Offline
Posting Whiz

Re: Combo box selection problem

  #6  
Oct 31st, 2006
never mind.
Last edited by waynespangler : Oct 31st, 2006 at 9:41 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 1:19 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC