Populate ComboBox items when user clicks dropdown

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
 
J

Jared

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.
 
I

illegal.prime

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
 
J

Jared

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top