mercredi 21 décembre 2016

1 Button 4 Comboboxes On Win Form

I have 1 button that will execute a stored procedure based off which combobox has data in it. Are multiple if statements the best course for me to account for each combobox scenario? I currently have my code like so - which works, but is a bit slow. Is there a better way to write this syntax using C# and VS2013?

private void btn1_Click()
{
    if (cbo1.Text.ToString() == "" && cbo2.Text.ToString() == "" && cbo3.Text.ToString() == "" && cbo4.Text.ToString() == "" )
  { 
    MessageBox.Show("You failed to make a selection.");
    return;
  }
  if (cbo1.Text.ToString() != "" && cbo2.Text.ToString() == "" && cbo3.Text.ToString() == "" && cbo4.Text.ToString() == "" )    
  {
    //Go route1 
  }
  if (cbo1.Text.ToString() == "" && cbo2.Text.ToString() 1= "" && cbo3.Text.ToString() == "" && cbo4.Text.ToString() == "" )    
  {
    //Go route2 
  }
  if (cbo1.Text.ToString() == "" && cbo2.Text.ToString() == "" && cbo3.Text.ToString() != "" && cbo4.Text.ToString() == "" )    
  {
    //Go route3 
  }
  if (cbo1.Text.ToString() == "" && cbo2.Text.ToString() == "" &&  cbo3.Text.ToString() == "" && cbo4.Text.ToString() != "" )   
{
      //Go route4 
  }

}

Aucun commentaire:

Enregistrer un commentaire