Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box 2

Status
Not open for further replies.

Mukesh2375

Programmer
Jan 31, 2003
19
0
0
IN
can i set height of a ComboBox (cb) control
exactly equal to the space required by the total no. of items in the combo box so that the ComboBox does not scroll.
cb.style = 1 Simple Combo

 
Surely, you mean a listbox.

You cannot change the height of a combobox.

Obviously you need to check if the height of the listbox exceeds the height of your form.

this doesnt produce exact results, but you can tweak it :

if List1.ListCount Then
List1.Height = List1.ListCount * 240
 
Mukesh2375
This code courtesy of strongm in thread222-438535 shows what you want to do...

Code:
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Private Sub Command1_Click()
    Form1.ScaleMode = vbPixels
    MoveWindow Combo1.hwnd, Combo1.Left, Combo1.Top, Combo1.Width, 320, True
End Sub
Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Dear RichardF,
seems you have not read my post till end. i had mentioned that i m using the combo box with style = 1. in this style you can definitely change the height of the combo box.
 
Dear mattNight,

seems U 've not got my Q correctly, u 've just changed the scalemode property of the form and assigned the combobox a specific width(320). But my question is specific; i want to set the height (...and not the width) of combo box to occupy exactly the items in the combo.

thanx anyway
MKS
 
Mukesh2375 - I see that you have started 4 threads and have yet to say thank you or to indicate that any post has been helpful. You don't seem to have made any posts in other member's threads either.

Since you're fairly new to the forum, yet may not be aware that Tek-Tips is a forum by and between professionals, it is not a tech support site, and its a good practice to share as you can with other members of the forum and to show professional courtesy when warranted.

Having said that, try this:

Combo1.Height = (Combo1.ListCount + 1) * 240

if you are using default font - if not you will have to adjust the 240 to suit
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thanx a lot johnwm,

this is exactly what i wanted.
yes U got me right. i m new 2 this forum and started by posting a few of my queries in the forum. i understatnd its a good practice to share as much as you can with other members of the forum and to show professional courtesy when warranted. i hope 2 keep up the courtesy 2 my best possible level.

thanx again.
MKS

 
Mukesh,

My apologies, i did not know this until i just tried it.

You learn something new everyday.
 
And here's a longer version that doesn't worry what font you have selected, and optionally makes sure that the resized combo doesn't overflow it's container:
[tt]
Public Sub MaximiseComboHeight(TargetCombo As ComboBox, Optional ByVal RestrictToContainer As Boolean = True)
Dim OldFont As Font
Dim NewHeight As Long

With TargetCombo
Set OldFont = .Parent.Font
Set .Parent.Font = TargetCombo.Font
NewHeight = (.ListCount + 2) * .Parent.TextHeight("M")

If (.Top + NewHeight > .Container.Height) And RestrictToContainer Then
NewHeight = .Container.Height - .Top - .Parent.TextHeight("M")
End If
.Height = NewHeight
Set .Parent.Font = OldFont
End With
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top