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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box: number of lines shown at once 4

Status
Not open for further replies.

kcorrigan

Programmer
May 30, 2002
50
0
0
US
My manager has requested that I change the number of items showing on a combo box in my program from the normal 8 to a larger number. In other words, she wants to be able to see more data at a time when she clicks on the arrow. Is this possible?
 
strongm,
I started over and tried your suggestion again and it did work! It didn't make sense to me that the other solution I found worked and the coding was so close to matching what you had. Since your code is shorter than the other solution I found, I will go with it. Problem solved! Thanks!
 
Sorry to breathe life into this old topic, but I can't get it to work. The flow of my code is:
Sub combo1_GotFocus()
*populate control with .AddItem....
*drop down list with call to SendMessage()
End Sub

I've tried placing the MoveWindow code at all different stages of my Sub (even prior to the Sub), all to no avail. In every test, the control vanishes from my form when the MoveWindow() gets called. It doesn't come back when focus is lost. The style of my combo is '2-dropdown list'. Could this matter? Should it matter what state the combo is in, or whether it has focus, or whether it has been populated yet?
Also, does combo1.Height only indicate the height of the combo when expanded? Why then does my properties window indicate that this number is the control height when compressed?? Curious....
I did find some samples on the Net, and they all work as advertised on my system (VB6 SP5 on W2K).

I've been actively searching for an in-depth description of programming this control... nothing yet - hence this post.
 
MinnKota,
I believe that the ListRows property is only available if you use the ComboBox control from the Microsoft 2.0 Forms Object library. It's not available on the standard VB6 control.

As this is the VB6 forum, the assumption would be that it's the standard control that they are talking about. Having said that, you can still use the Forms Object library controls, subject to the licensing limitations, and hence the slightly messy installation procedure needed to ensure that the library is available on your clients machines.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
>does combo1.Height only indicate the height of the combo when expanded?

No, it indicates the height of the Edit part of the combo box (what you are calling the 'compressed' bit). The height is expressed in the units of the scale mode of its container.

>control vanishes from my form when the MoveWindow() gets called

As presented, this shouldn't happen. But then I can't actually see how you are using it from your code example

>'2-dropdown list'. Could this matter? Should it matter what state the combo is in, or whether it has focus, or whether it has been populated yet?

'No' to all of those
 
I don't know if my tiny bit might help. It works for me. Try this.

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

Public Sub SizeCombo(frm As Form, cbo As ComboBox)

' Resize a ComboBox's dropdown display area.
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

' Calculate the new height of the combo box.
cbo_height = frm.ScaleHeight - cbo.Top - 5
frm.ScaleMode = old_scale_mode

' Resize the combo box window.
MoveWindow cbo.hWnd, cbo_left, cbo_top, _
cbo_width, cbo_height, 1

End Sub

Private Sub Command1_Click()
For ty = 1 To 100
Form1.Combo1.AddItem ty
Next
End Sub

Private Sub Form_Load()
SizeCombo Me, Combo1
End Sub

The above is fine, other than a word of warning as I found out. The sizecombo alters the scaling so if you have controls programtically positioned, then putting in the call should follow those settings. Hope it helps, would be good to give back something to this site. Regards
 
If it is relevant ?

The code works fine but it can 'fail' (sic) depending on what order I do things in.

If I open the list of values before selecting Command1 (I get the 8 values) and then I select Command1 while the list of values is still visible I still get the 8 values.

If I select Command1 while the LOV is closed up and then open it up I get all 13 values i loaded.

 
Hmmm - I get same symptoms as mscott - control disappears. I have also tried in various places in code. Any suggestions?

Thanks in advance.
 
thread222-797395 - is really what I was looking for and resolves problem
 
Can you start a new project and duplicate the problem, then post code here so we can play with it?

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
I'm running out of time today but will take a note and try to reproduce when I get the opportunity.
 
Hehe thx strongm. I just ran into the same problem and you're code works like a charm!

.DaviD.

 
Glad to have been of assistance. It what these forums are all about
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top