Asked by:
Convert a string to Chart type in VB.Net

Question
-
Hi,
How to convert a string to Chart type like below in VB.NET syntax?
ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), comboBoxChartType.Text, true);
Since i will store only the type as column or line in table and retrieve and convert to SeriesCharttype.Line or Column
Thanks,
Senthil
Friday, January 7, 2011 7:52 AM
All replies
-
You can try the Below one,
YourChart.ChartType = DirectCast([Enum].Parse(GetType(SeriesChartType), comboBoxChartType.SelectedItem.ToString(), True), SeriesChartType)
Hope this will work.
Regards,
RajeshS.Friday, January 7, 2011 10:44 AM -
Hi Rajesh,
I think you have tried with code conversion but i tried already which didn't work.
Thanks,
Senthil
Friday, January 7, 2011 2:51 PM -
try this in an app with two ComboBoxes and a Chart on the Form. See if it works how you want.
Change the selection in each ComboBox to switch between Line and Column. The ComboBox selected item (Line or Column) would be the same as getting the string value from a Table.
you could also store the Enum value in the table instead of the name and use that to change the Chart type, as shown in the ComboBox2 event.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.Items.AddRange({"Line", "Column", "Point", "StepLine"}) ComboBox2.Items.AddRange({3, 10, 0, 5}) Dim rndm As New Random For i As Integer = 1 To 10 Chart1.Series(0).Points.AddY(rndm.Next(1, 21)) Next End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged 'set ChartType using Enum Name as String from ComboBox1 Chart1.Series(0).ChartType = [Enum].Parse(GetType(SeriesChartType), ComboBox1.SelectedItem.ToString) End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged 'set ChartType using Enum Value as Integer from ComboBox2 Chart1.Series(0).ChartType = CType(CInt(ComboBox2.SelectedItem), SeriesChartType) End Sub
Saturday, January 8, 2011 3:18 AMModerator -
Great !! Many Thanks, It worked !!Tuesday, January 25, 2011 11:57 AM