Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SelectedIndexChanged-Event of ComboBox

I have a ComboBox with two read only values: white fusion and silver fusion.
How do I get the correct method to run based on selecting each one in a ComboBox? The methods are just pulling an Integer from a SQL table and put it into a TextBox.

private void cboOilVehicle_SelectedIndexChanged(object sender, EventArgs e)
{
    if (cboVehicle.SelectedIndexChanged == "White Fusion")
    {
        whiteFusionOil();
    }
    else
    {
        silverFusionOil();    
    }
}
like image 470
Sealer_05 Avatar asked Dec 10 '22 02:12

Sealer_05


1 Answers

private void cboOilVehicle_SelectedIndexChanged(object sender, EventArgs e)
{
  if (cboVehicle.SelectedIndex == 0)
  {
    whiteFusionOil();
  }
  else
  {
    silverFusionOil();    
  }
}

Edit:

The name of the control must be cboOilVehicle (Line 1) or cboVehicle (Line 3), it can't be both. You have to decide which is correct

like image 176
Eugen Rieck Avatar answered Dec 24 '22 17:12

Eugen Rieck