-
Oct 23rd, 2012, 10:07 PM
#1
Thread Starter
New Member
How to code Radio Buttons to change value in DropDown Combobox?
This has been mind boggling me for awhile, and I cannot seem to get around it. Hopefully someone here will be helpful enough to answer my question.
I would like to know what/how to code a radio button that when selected it changes the Collection values in the combobox.
Pretty much I have two radio buttons inside a groupbox with a combobox below it. One radio button is "Province" and the other "Territory". What I would like to know is how would I go about when the user selects the Province radio button that in the combobox it shows the provinces of Canada, and when they select the Territory radio button that the combobox will update and show the three territories of Canada.
If no one understands I will post screenshots of what I mean.
Thank You.
-
Oct 23rd, 2012, 10:29 PM
#2
Re: How to code Radio Buttons to change value in DropDown Combobox?
can you post a list of your provinces + territories?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 23rd, 2012, 10:32 PM
#3
Thread Starter
New Member
Re: How to code Radio Buttons to change value in DropDown Combobox?
Provinces(A-Z)
Alberta
British Columbia
Manitoba
New Brunswick
Newfoundland & Labrador
Nova Scotia
Ontario
Prince Edward Island
Quebec
Saskatchewan
Territories
Northwest Territories
Nunavut
Yukon
-
Oct 23rd, 2012, 10:39 PM
#4
Re: How to code Radio Buttons to change value in DropDown Combobox?
try this:
vb.net Code:
Public Class Form1
Dim choices()() As String = {New String() {"Alberta", "British Columbia", "Manitoba", "New Brunswick", "Newfoundland & Labrador", "Nova Scotia", "Ontario", "Prince Edward Island", "Quebec", "Saskatchewan"}, New String() {"Northwest Territories", "Nunavut", "Yukon"}}
Private Sub RadioButtons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged
Dim rbs() As RadioButton = {RadioButton1, RadioButton2}
ComboBox1.DataSource = choices(Array.IndexOf(rbs, sender))
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RadioButton1.Checked = True
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 23rd, 2012, 10:45 PM
#5
Thread Starter
New Member
Re: How to code Radio Buttons to change value in DropDown Combobox?
Alright, and where would this code go in, the combobox, form, or both the radio buttons?
-
Oct 23rd, 2012, 10:47 PM
#6
Re: How to code Radio Buttons to change value in DropDown Combobox?
show me your form code + i'll show you how to integrate my code
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 23rd, 2012, 10:55 PM
#7
Thread Starter
New Member
Re: How to code Radio Buttons to change value in DropDown Combobox?
There, I believe that's what you asked.
I only have two buttons coded how they should be.
-
Oct 23rd, 2012, 10:59 PM
#8
Re: How to code Radio Buttons to change value in DropDown Combobox?
ok. you can paste the code before your first button_click handler.
don't forget to change the names RadioButton1, RadioButton2 to your rb names
edit: + the combobox...
Last edited by .paul.; Oct 23rd, 2012 at 11:02 PM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 23rd, 2012, 11:01 PM
#9
Re: How to code Radio Buttons to change value in DropDown Combobox?
in your code, intResponse is wrong. a msgbox returns a value of type msgboxresult
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 23rd, 2012, 11:04 PM
#10
Thread Starter
New Member
Re: How to code Radio Buttons to change value in DropDown Combobox?
Thank you very much, Paul. +1 rep for you.
-
Oct 23rd, 2012, 11:37 PM
#11
Re: How to code Radio Buttons to change value in DropDown Combobox?
Another very simple way to do this would be to use two combo boxes and toggle which is visible when the radio button is ticked.
-
Oct 23rd, 2012, 11:46 PM
#12
Thread Starter
New Member
Re: How to code Radio Buttons to change value in DropDown Combobox?
Originally Posted by DataMiser
Another very simple way to do this would be to use two combo boxes and toggle which is visible when the radio button is ticked.
And how would that work? I am thinking of doing another assignment in the future and will use the Combobox like this and I think I will use both.
-
Oct 24th, 2012, 06:52 AM
#13
Re: How to code Radio Buttons to change value in DropDown Combobox?
You should be able to figure that out if you give if a tiny bit of thought. You have 2 lists and 2 combos you want one list visible based on which radio button is clicked. Think about it.
-
Oct 24th, 2012, 07:18 AM
#14
New Member
Re: How to code Radio Buttons to change value in DropDown Combobox?
Originally Posted by MattJoey
And how would that work? I am thinking of doing another assignment in the future and will use the Combobox like this and I think I will use both.
Heres how you do it, just have the combo boxes directly over each other
Code:
Private Sub Provinces_Radio_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Provinces_Radio.CheckedChanged Provinces_Combo.Visible = True
Territories_Combo.Visible = False
End Sub
Private Sub Territories_Radio_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Territories_Radio.CheckedChanged
Territories_Combo.Visible = True
Provinces_Combo.Visible = False
End Sub
-
Oct 24th, 2012, 07:20 AM
#15
New Member
Re: How to code Radio Buttons to change value in DropDown Combobox?
Why....did it do that? :/
and why cant I edit?
Code:
Private Sub Provinces_Radio_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Provinces_Radio.CheckedChanged
Provinces_Combo.Visible = True
Territories_Combo.Visible = False
End Sub
Private Sub Territories_Radio_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Territories_Radio.CheckedChanged
Territories_Combo.Visible = True
Provinces_Combo.Visible = False
End Sub
-
Oct 24th, 2012, 07:21 AM
#16
Re: How to code Radio Buttons to change value in DropDown Combobox?
Why did it do what?
You can't edit until your post count is a bit higher.
-
Oct 24th, 2012, 07:23 AM
#17
New Member
Re: How to code Radio Buttons to change value in DropDown Combobox?
Originally Posted by DataMiser
Why did it do what?
You can't edit until your post count is a bit higher.
On my screen on the first reply I made the first and seconds CODE lines are on the same line.
and thanks for the info about the edit.
-
Oct 24th, 2012, 07:28 AM
#18
Re: How to code Radio Buttons to change value in DropDown Combobox?
The code window will word wrap when the lines are to long to fit.
-
Sep 18th, 2013, 07:21 PM
#19
New Member
Re: How to code Radio Buttons to change value in DropDown Combobox?
I am having also the same problem. I need to save what is in the radio button like save male or female? I am using streamwriter to save the details of the form.
-
Sep 18th, 2013, 07:37 PM
#20
Re: How to code Radio Buttons to change value in DropDown Combobox?
Originally Posted by krazy4search
I am having also the same problem. I need to save what is in the radio button like save male or female? I am using streamwriter to save the details of the form.
Please start your own thread for your question.
This thread is 11 months old
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
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
|