Try this. Their might be a space on the end of the string
if (comboBox1.SelectedItem.ToString().Trim() == "DOCTOR DETAILS")
{
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am doing my window form project, in which I am using the combo box control.
private void button5_Click(object sender, EventArgs e)
{
con.Open();
if (comboBox1.SelectedItem.ToString() == "DOCTOR DETAILS")
{
Form2 f2 = new Form2();
f2.Show();
}
else if (comboBox1.SelectedItem.ToString() == "PATIENT DETAILS")
{
Form3 f3 = new Form3();
f3.Show();
}
else if (comboBox1.SelectedItem.ToString() == "OPTICAL DETAILS")
{
Form4 f4 = new Form4();
f4.Show();
}
else if (comboBox1.SelectedItem.ToString() == "FEEDBACK DETAILS")
{
Form5 f5 = new Form5();
f5.Show();
}
else
MessageBox.Show("no table is selected");
con.Close();
}
This is the code I have written when I debug it show form3,form4 and form5 but when I select the DOCTOR DETAILS in the combo box it doesn't show me the form1 instead it show message box that "no table is selected".
so anyone pls tell me what mistake I have made and how to rectify it.
Try this. Their might be a space on the end of the string
if (comboBox1.SelectedItem.ToString().Trim() == "DOCTOR DETAILS")
{
Hi KMOHANAPRIYA,
Please confirm if the item is exactly equal to "DOCTOR DETAILS".
You could define a value for selected item, then set a breakpoint at judgement condition to help you check it:
Best Regards,
Dylan