bwk5502
08-09-2000, 12:31 AM
In VB6 Learning Edition, I want to increase the Combo drop down size from 8 to 10 (i.e. instead of showing 8 lines when dropped down, I want to show 10 lines)
I've looked for hours in all the help stuff and I can't find the answer. Can someone please help me with this?
karimahta
08-09-2000, 03:28 AM
This is the easiest way I have found, so far...
<TABLE BORDER=2><TR><TD><font color=red>Please note, most of this example comes from the site: <A HREF="http://www.vb-helper.com/HowTo" target="_new">http://www.vb-helper.com/HowTo</A> and the actual example file is called combohgt.zip.
However, for this example I have modified the code so that you can select the number of rows to display in your combo.</font color=red></TD></TR></TABLE>
Paste this into a form with a combo box called "cbo"...<CODE><PRE>Option Explicit
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 Form_Load()
Dim i As Integer
' Make a bunch of ComboBox entries.
For i = 1 To 50
cboTestCombo.AddItem Format$(i)
Next i
cboTestCombo.ListIndex = 0
' Resie the ComboBox's dropdown area.
SizeCombo Me, cboTestCombo, 15
End Sub
' Resize a ComboBox's dropdown display area.
Public Sub SizeCombo(frm As Form, cbo As ComboBox, ByVal NumberOfRows As Long)
Const ADJUST_3D = 4
Dim cbo_left As Integer
Dim cbo_top As Integer
Dim cbo_width As Integer
Dim cbo_height As Integer
Dim old_scale_mode As Integer
' Change the Scale Mode on the form to Pixels.
old_scale_mode = frm.ScaleMode
frm.ScaleMode = vbPixels
' Save the ComboBox's Left, Top, and Width values.
cbo_left = cbo.Left
cbo_top = cbo.Top
cbo_width = cbo.Width
''cbo_height = frm.ScaleHeight - cbo.Top - 5
' Calculate the new height of the combo box.
cbo_height = cbo.Height + (Me.TextHeight("A") * NumberOfRows) + ADJUST_3D
frm.ScaleMode = old_scale_mode
' Resize the combo box window.
MoveWindow cbo.hwnd, cbo_left, cbo_top, _
cbo_width, cbo_height, 1
End Sub</CODE></PRE>
HTH
bwk5502
08-26-2000, 10:20 PM
I am using SizeCombo (Public) and MoveWindow as suggested to re-size my combo drow downs. They are in Module1 which has Option Explicit. The Me in SizeCombo had to be changed to frm. The combo re-size works well in form1 but the combo size for form2 doesn't change. No error messages. Can you please tell me what to do to make the SizeCombo procedure effective for form2? Thanks.
karimahta
08-26-2000, 11:27 PM
If you are calling the procedure the same way as in form1, it should work!.
You do have to call the SizeCombo from within Form2s somehwere.
Other than that, I don't know where it might be going wrong.
I have tried it with two forms and it works fine (after fixing the Me. problem)
HTH
bwk5502
08-27-2000, 05:07 PM
Well I've just about worn myself out on this one, but I do have some questions. I call SizeCombo exactly the same in form2 as I do in form1, and I'm sure I'm doing that right. It does not change the drop-down rows, but at execution, each of the boxes that are named in a SizeCombo argument are all left with the box window highlighted. ??? This would indicate the the procedure is as least executed for the boxes.
Since this problem is only related to form2, is it likely that the form (or the project data) is corrupt? If so, is there a utility or procedure for testing and correcting suspect objects? I have tried copy and paste of form2 items to a new form (form3), but that didn't help either.
This is the pits. Any additional ideas would be appreciated. Thanks.
bwk5502
08-28-2000, 09:40 AM
Well I didn't give up. After analyzing my code for two days, I concluded there was nothing wrong with the code in form2. Must be the form2 layout. I created a new form (form3) and added all new combo boxes, etc., (took a long time). I gave the new objects the same names as in the old form2, and I copied the form2 code into form3. Now the SizeCombo works in form3 as well as form1.
So what went wrong? All I can think of is that form2 was the first form I tried to lay out, and I must have done things that beginners do to their new programs.... unexpected actions that find bugs in software languages. I played around with different layout grids which may have resulted in odd settings which the SizeCombo procedure didn't like.
All is well now (so far), and thanks all,
Bil