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.
Re: How to code Radio Buttons to change value in DropDown Combobox?
can you post a list of your provinces + territories?
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
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
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?
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
2 Attachment(s)
Re: How to code Radio Buttons to change value in DropDown Combobox?
Attachment 92607Attachment 92609
There, I believe that's what you asked.
I only have two buttons coded how they should be.
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...
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
Re: How to code Radio Buttons to change value in DropDown Combobox?
Thank you very much, Paul. +1 rep for you. :)
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.
Re: How to code Radio Buttons to change value in DropDown Combobox?
Quote:
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.
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.
Re: How to code Radio Buttons to change value in DropDown Combobox?
Quote:
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
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
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.
Re: How to code Radio Buttons to change value in DropDown Combobox?
Quote:
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. :)
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.
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.
Re: How to code Radio Buttons to change value in DropDown Combobox?
Quote:
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