title: C# Windows Forms, Combobox MouseClick event getting fired multiple times
body: <p>I have a windows form with many controls. A tiny part of it is logging in to an SQL server and fetching the list of database names and assigning the collection to a combobox.</p>
  
  <pre><code>    private void InitializeComponent()
      {
  
          //...
          //...
          this.ServerTB = new System.Windows.Forms.TextBox();
          this.UserNameTB = new System.Windows.Forms.TextBox();
          this.PasswordTB = new System.Windows.Forms.TextBox();
          //...
          //...
  
          this.ServerTB.TextChanged += new System.EventHandler(this.OnSQLServerChanged); 
          this.UserNameTB.TextChanged += new System.EventHandler(this.OnSQLServerChanged);     
          this.PasswordTB.TextChanged += new System.EventHandler(this.OnSQLServerChanged);     
  
  
          this.DatabaseCmbBox = new System.Windows.Forms.ComboBox();
          //...
          //...
          this.DatabaseCmbBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.DatabaseCmbBox_Click);
  
          //....
  
      }
  
      private void DatabaseCmbBox_Click(object sender, MouseEventArgs e)
      {
          MessageBox.Show(sender.GetType().ToString());
  
          this.Cursor = Cursors.IBeam;
  
          List&lt;string&gt; dbList = new List&lt;string&gt;();
  
          dbList = GetDatabaseList();
  
          DatabaseCmbBox.DataSource = dbList;
  
          DatabaseCmbBox.SelectedIndex = -1;
  
  
          if (dbList.Count &gt; 0)
          {
              DatabaseCmbBox.MouseClick -= DatabaseCmbBox_Click;
          }
  
  
          DatabaseCmbBox.Focus();
  
          this.Cursor = Cursors.Default;
      }
  
      protected List&lt;string&gt; GetDatabaseList()
      {
          List&lt;string&gt; list = new List&lt;string&gt;();
  
          string conString = "server=" + ServerTB.Text + ";uid=" + UserNameTB.Text + ";pwd=" + PasswordTB.Text + "; database=master";
  
          try
          {
  
              using (SqlConnection con = new SqlConnection(conString))
              {
                  con.Open();
  
                  using (SqlCommand cmd = new SqlCommand("select name from sys.databases where name not in ('master', 'model', 'tempdb', 'msdb') ", con))
                  {
                      using (IDataReader dr = cmd.ExecuteReader())
                      {
                          while (dr.Read())
                          {
                              list.Add(dr[0].ToString());
                          }
  
                          dr.Close();
                      }
  
                      cmd.Dispose();
                  }                    
  
                  con.Close();
              }
          }
          catch(SqlException ex)
          {
              DatabaseCmbBox.MouseClick -= DatabaseCmbBox_Click;
              MessageBox.Show(ex.Message);
              ServerTB.Focus();
          }
  
          return list;
  
      }
  
      private void OnSQLServerChanged(object sender, EventArgs e)
      {
          DatabaseCmbBox.MouseClick += DatabaseCmbBox_Click;
      }
  </code></pre>
  
  <p>I don't have a problem in fetching the list of Databases. It takes about 10 seconds to do so. With the messagebox in the event handler, I found out that the MouseClick event, for no apparent reason, gets fired like 38 times. The same thing happens even if I use the Enter event or Click event, instead of the MouseClick event.</p>
  
  <p>Why does this happen, and how does one go about using these kind of events?</p>
  
  <p>Thanks in advance, 
  RPS.</p>