I am trying to display the result from an if statment which is based upon the option selected within a windows form combo box.
I am having issues when the if statment is placed within its own class seperate to the form and is always just returning the else value. I have made the combobox public.
My code is as follows.
public void button1_Click(object sender, EventArgs e)
{
xRayData xRayData1 = new xRayData();
string shiftChangeValue;
shiftChangeValue = xRayData1.shiftChange();
label2.Text = shiftChangeValue;
}
public string shiftChange()
{
frmSWChange frmSWChange1 = new frmSWChange();
string shiftLetter;
if (frmSWChange1.cbShift.Text == "Day")
{
shiftLetter = "D";
}
else if (frmSWChange1.cbShift.Text == "Night")
{
shiftLetter = "N";
}
else if (frmSWChange1.cbShift.Text == "Morning")
{
shiftLetter = "M";
}
else
{
shiftLetter = "ERROR";
}
return shiftLetter;
}
Use
Selected...for getting the selected item in combobox