I have a combo box
that I'm using to select a month out of a year. The months are provided through a List<>
that I've set as the data source
.
I believe I'm going about this the wrong way.
Code So Far:
private void btnExport_Click(object sender, EventArgs e)
{
int month = 0; //just a default value
if (cbMonth.SelectedText == "January")
month = 1;
else if (cbMonth.SelectedText == "Febuary")
month = 2;
else if (cbMonth.SelectedText == "March")
month = 3;
else if (cbMonth.SelectedText == "April")
month = 4;
else if (cbMonth.SelectedText == "May")
month = 5;
else if (cbMonth.SelectedText == "June")
month = 6;
else if (cbMonth.SelectedText == "July")
month = 7;
else if (cbMonth.SelectedText == "August")
month = 8;
else if (cbMonth.SelectedText == "September")
month = 9;
else if (cbMonth.SelectedText == "October")
month = 10;
else if (cbMonth.SelectedText == "November")
month = 11;
else if (cbMonth.SelectedText == "December")
month = 12;
int year = Int32.Parse(mtbYear.Text);
MessageBox.Show(month.ToString() + " " + year.ToString()); // to check values
}
My month
never changes value and displays as 0
. Which, I understand because I had given it the initial value of 0
in order to pass it to another method.
Question: How can I get the numeric value for the months when the user selects them from my combo box?