title: If else statement between two combobox using c#
body: <p>I implemented two Combobox in my coding. 1st combobox contain the city name and the 2nd combobox contain the POI of that city. Now I want to implement if else statement between this two combobox. Suppose if I select 1st combobox, Button will enable only for 1st one, then if I select 2nd Combobox then Button will work for 2nd one. I do not know how to do it. My code is like this</p>
  
  <pre><code>public void Download_Click(object sender, EventArgs e)
  {
     // if combox1 select
     // all function will work for combobox 1
  
     //else if combobox2 select
     //combobbox1 disabled and all function will work for combobx2    
  }
  </code></pre>
  
  <p>Initially I created class to set the value of combobox1 like this</p>
  
  <pre><code>            class PlaceList
                  {
  
                      public static ComboBox Combo_list = new ComboBox();
                      public static DataGridView dataTable = new DataGridView();
  
                      public static void List()
                      {
  
                          var startPath = Application.StartupPath;
                          string folderName = Path.Combine(startPath, "POI_List");
                          System.IO.Directory.CreateDirectory(folderName);
                          string SavedfileName = "POI_list.json";
                          var Saving_path = Path.Combine(folderName, SavedfileName);
  
                          string fileName = "Zensus_Gemeinden_org.xlsx";
                          var path = Path.Combine(startPath, fileName);
  
                          String name = "Gemeinden_31.12.2011_Vergleich";
                          String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
                                         path + ";Extended Properties='Excel 12.0 XML;HDR=YES;';";
  
                          OleDbConnection con = new OleDbConnection(constr);
                          OleDbCommand oconn = new OleDbCommand("Select [3] as City,[4] as Population, * From [" + name + "$D7:E11300] Where [4] &gt; 10000", con);
                          con.Open();
  
                          OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
                          DataTable data = new DataTable();
  
                          sda.Fill(data);
                          dataTable.DataSource = data;
  
  
  
                          for (int i = 0; i &lt; data.Rows.Count; i++)
                          {
                              Combo_list.Items.Add(data.Rows[i]["City"]);
                          }
  
  
                          string Place_Json = "Place_List:" + JsonConvert.SerializeObject(data, Formatting.Indented);
                          File.WriteAllText(Saving_path, Place_Json);
  
                      }
                  }
     }
  </code></pre>
  
  <p>Then in Form1.cs I created</p>
  
  <pre><code>   Dictionary&lt;string, List&lt;string&gt;&gt; poi = new Dictionary&lt;string, List&lt;string&gt;&gt;();
  
  
      private void LoadKeys()
      {
  
         foreach (string line in File.ReadLines("TextFile1.txt"))
                  {
                      string[] parts = line.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                      poi.Add(parts[0], new List&lt;string&gt;());
                      poi[parts[0]] = new List&lt;string&gt;(parts.Skip(1));
                  }
  
      }
  
      void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
      {
          if (comboBox1.SelectedItem != null)
          {
              string txt = comboBox1.SelectedItem.ToString();
              if (poi.ContainsKey(txt))
              {
                  List&lt;string&gt; points = poi[txt];
                  comboBox2.Items.Clear();
                  comboBox2.Items.AddRange(points.ToArray());
              }
          }
      }
  </code></pre>
  
  <p>That means combobox2 is dependent of combobox1. It will give the places name accoerding to the combobox1</p>
  
  <p>then finally in form1.cs button 1 I am trying to do this somethis like this</p>
  
  <pre><code>    public Form1()
      {
  
          InitializeComponent();
  
  
          PlaceList.Combo_list = comboBox1;
          PlaceList.List();
          LoadKeys();
  
  
      }
  
  
      private void button1_Click(object sender, EventArgs e)
      {
  
          if (comboBox1.SelectedIndex != 0)
          {
              ShortText.txt1 = richTextBox1;
              ShortText.shortText(comboBox1.Text);
          }
          else if (comboBox2.SelectedIndex != 0)
          {
              ShortText.txt1 = richTextBox1;
              ShortText.shortText(comboBox2.Text);
          }
          else
          {
              MessageBox.Show("Error");
          }
  </code></pre>