Populate ComboBox items when user clicks dropdown

  • Thread starter Thread starter illegal.prime
  • Start date Start date
I

illegal.prime

Hi all, I want to set up a ComboBox that will add all its items
whenever a user clicks on the ComboBox. I've tried doing it on the
MouseDown or OnClick events - but that seems too late. For example,
if the ComboBox previously had one item and then it ends up with two
items when the user clicks on it - it ends up with a scroll bar - that
is necessary to scroll between the two items. I've tried added a
Refresh and/or Invalidate method invocation after adding the items to
no avail.

Is there either:
a) An earlier event I can tie into - so that the control properly
rebuilds itself - i.e. no scroll bar for two items situation
b) Something I can do after adding the items to "refresh" the drop
down list - so that unnecessary scroll bar isn't added?

Thanks,
Novice
 
Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ComboBox1.DropDown

Me.ComboBox1.Items.Add("item2")



End Sub



But why?, almost sounds unlogical to me.
 
Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ComboBox1.DropDown

Me.ComboBox1.Items.Add("item2")

End Sub

But why?, almost sounds unlogical to me.

Hmm... I thought I had tried the DropDown event as well and I thought
it yielded the same result as the OnClick and MouseDown - i.e. if I
add an element at that point the drop down list will get an
unnecessary scroll bar. For example, if I had one item in the list
already, then clicked on the combo box (and it added a new one) - I
would get a scroll bar for two items - I don't want that. I'll give
it a try tomorrow.

As for the why - it is because the entire list of items can be
modified at any point in time by many different things.

Novice
 
I can not repeat the behaviour you are having with scroll bar. But you
should look into couple of propereties..

[NET20]
ComboBox.DropDownHeight
ComboBox.DropDownStyle
 
Back
Top