| | |
Combo box selection problem
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2005
Posts: 14
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Mar 2005
Posts: 14
Reputation:
Solved Threads: 0
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
•
•
•
•
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
•
•
•
•
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
•
•
•
•
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
Thanks
Cristy
•
•
Join Date: Jun 2006
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
I always feel shorter is better so just add .clone onto your dose
VB.NET Syntax (Toggle Plain Text)
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
•
•
Join Date: Oct 2006
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
I always feel shorter is better so just add .clone onto your dose
VB.NET Syntax (Toggle Plain Text)
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
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
![]() |
Similar Threads
- Combo box problem (Java)
- Perplexed: Combo Box Not Holding Data (C#)
- combo box (PHP)
- combo box help (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Dataset to Listbox for selection by user
- Next Thread: Audio Conversion
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic binary bing box button buttons click code combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists file-dialog firewall folder google hardcopy image images isnumericfuntioncall login math memory mobile module ms msaccess mssqlbackend mysql navigate net networking opacity output peertopeervideostreaming picturebox1 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog serial sqldatbase storedprocedure string temp text textbox timer toolbox updown useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml





