views:

438

answers:

1

Urgh, I have spent the last couple of hours on this now. I normally end up finding the answer from a bit of Googling, but not with this one. Bit of a headache.

My questions:

  1. How can I catch when a user clicks the dropdown arrow on a combobox and prevent the dropdown list from being displayed.

  2. How can I then clear and populate the dropdown list and display it programmatically?

I have one agent program remotely connected to a server over the internet. When you click the dropdown arrow on the agent, it queries the server to determine what needs to be in the dropdown list. It then displays the dropdown list. The comboboxes act as filters for the subsequent comboboxes on the GUI. A delay in displaying the dropdown list is perfectly acceptable while retrieving the data. Initially querying all the possibly entries in the dropdown list is not an option because there are so many! Needs to be comboboxes compared to listboxes as the user may also type an entry that is not in the list.

Hopefully this will clarify what I am doing:

GUI on the agent:

ComboBox1 - displays the countries

ComboBox2 - displays the cities - dropdown list determined by ComboBox1 selected item

ComboBox3 - displays the towns - dropdown list determined by ComboBox2 selected item

ComboBox4 - displays the streets - dropdown list determined by ComboBox3 selected item

+1  A: 

Instead of populating the drop down when the user clicks the drop down button I would suggest that you populate and enable the following combo box when the value of the previous combo box changes. If populating the combo box is slow the delay is much more pleasant after the user has selected a value than before the user is going to select a value.

Assuming you are using Windows Forms here is a handler for the first combo box:

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  ComboBox2.Enabled = True
  ' Fill ComboBox2 based on ComboBox1.SelectedItem
  ComboBox2.Items.Clear()
  ComboBox2.Items.Add("Foo")
  ComboBox2.Items.Add("Bar")
End Sub

Note that ComboBox2 to ComboBox4 are disabled intially and only are enabled when they are filled with data.

Martin Liversage
I initially read it thought yeah, that's too simple, I already tried it, that won't work.But - thinking about it, it's actually the perfect solution that I should really have thought of to start with. Sometimes all it needs is a fresh pair of eye (and someone who knows what they're talking about!)All working great, thanks for the quick and helpful reply.
ezwi
I'd add "ComboBox2.Items.Clear();" before adding Foo and Bar here.
MusiGenesis
@MusiGenesis: You are right and I have edite my answer.
Martin Liversage