Gilan
Gilan

Reputation: 11

Height of Combo box drop down list

So this is a really stupid question but I can't figure it out, I have a Combo Box (aka Drop Down List) with Items that change frequently, normally the height of the Drop Down List is dependent on how many Items there are (just long enough to show all the Items) when you clear the Items, however the height of the Drop Down List remains at the height it was last time you opened it. It doesn't really mater but my OCD cannot accept this.

I use Visual Basic 10, and I am a Noob that has been using VB for about a month.

Update: I was playing around with this problem and I found one way to do it:

ComboBox1.Items.Clear()
ComboBox1.Items.Add("")
ComboBox1.Items.Remove("")

So it would appear that the combo box clear() call does not automatically set the Item count to 0 but when you enter another item it does, while this will work are there any better ways to do this?

Upvotes: 0

Views: 7240

Answers (3)

Gino
Gino

Reputation: 176

I would set the cb to a fixed height and let only the dropdown height be "dynamic".

Hope it helps

Upvotes: 0

Eli
Eli

Reputation: 11

ComboBox1.Items.Clear()
ComboBox1.Items.Add("")
ComboBox1.Items.Add("")
ComboBox1.Items.Add("")

ComboBox1.DropDownHeight = ComboBox1.Items.Count * ComboBox1.ItemHeight

Upvotes: 1

Gilan
Gilan

Reputation: 11

My answer is what I wrote in the update,

ComboBox1.Items.Clear()
ComboBox1.Items.Add("")
ComboBox1.Items.Remove("")

obviously the clear function doesn't re-size the drop down list? Anyway adding an item does so adding and removing an item triggers the Drop down list to re-size. I found you could also do it using the

ComboBox1.DropDownList.Height

however, it would appear that by manually setting the height you turn off the automatic Drop Down list height, so then you would have to manually resize it for all of the items, Something like this?

ComboBox1.DropDownList.Height = ComboBox1.Items.Count * ComboBox1.Items.Height

Upvotes: 1

Related Questions