Radio Button Value
How to get the value of a Radio Button label and use it in code.
I spent quite a bit of time trying to figure out how to get the Label text from a Radio Button and use it in my Code.
I wanted to change the type of Chart that was being displayed and wanted the user to have a set of options.
Add a Frame onto your Form. (GroupBox1)
Dim rButton As RadioButton
rButton = GroupBox1.Controls.OfType(Of RadioButton)()
.Where(Function(r) r.Checked = True).FirstOrDefault()
ChosenChart = rButton.Text
Chart1.Series(Series1.Name).ChartType =
[Enum].Parse(GetType(SeriesChartType), ChosenChart)
I tried the following but it didn't work.
'Chart1.Series(Series1.Name).ChartType = CType(ChosenChart, SeriesChartType)
Working With Charts? Add the following class.
Imports System.Windows.Forms.DataVisualization.Charting
Research
I found the following article which helped.
Chart1.Series(Series1.Name).ChartType =
DirectCast([Enum].Parse(GetType(SeriesChartType), ChosenChart, True), SeriesChartType)
By: Alex Hedley
Click here to sign up for more FREE tips
|