Shkolar
Shkolar

Reputation: 422

Winforms - Stop Dropdown of Combobox during DropDown event

I need to implement a ComboBox, which acts as follows:
When Click on the ComboBox, the client calling API method and updates the combobox items with the response.
My problem is, when I have 0 results - I want the ComboBox not to open (It has 0 items).
Is there a way to do that? This is my current code:L

private void Combo_DropDown(object sender, EventArgs e)
{
    // Private method which addes items to the combo, and returns false if no itmes were added
    if (!AddItemsToComboBox())
    {
        // This is not working
        Combo.DroppedDown = false;
    }
}

Upvotes: 1

Views: 2043

Answers (1)

user2480047
user2480047

Reputation:

You can make the DropDownHeight as small as possible (1). For example:

  int iniHeight;
  private void Form1_Load(object sender, EventArgs e)
  {
        iniHeight = Combo.DropDownHeight;
  } 

  private void Combo_DropDown(object sender, EventArgs e)
  {
        Combo.DropDownHeight = (AddItemsToComboBox() ? iniHeight : 1);
  }

Upvotes: 2

Related Questions