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?
 
Hi there,

It all depends on how that combo box is made.

1) If it is hard coded in the program then open up the project. Click on the combo box and then have a look in the properties window. There is a property there that is called 'list' and next to it is a down arrow like a combo box, click this and then at the bottom of the list simply add whatever you need. Then recompile and use that.

2) If it is done at runtime then simply use the following to add an item to the combo box.

cboCombo.AddItem("Item to add")

if I have got the wrong endd of the stick and its something else you mean then please shout up. If not then Have a great new year.


'mi casa es su casa'
]-=tty0=-[
ICQ:82621399
 
I'm actually not looking for "additem". Let me explain a little more, maybe that will help:

I have a sql script that populates this combo box. Let's say the script comes back with 30 records & they are all added to the box (I use the .additem code to do this actually).
What you then see on the screen is a combo box with all 30 records, but when you click the arrow to scroll, the most you see at one time is 8 records. She wants to see more than that at once. Does that clear it up?
 
I couldn't find a property to do this with the regular combo box, unlike in VB.Net, the MaxDropDownItems method.
 
Sure, Resize it to any height that you like. Here's an example that makes it 320 pixels high. Note that the combobox is smart; internally it limits the height so that you can never show a dropdown that could show more than the maximum number of items the combo is holding. The following assumes that you have a form with a combobox and a command button

[tt]
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
 
strongm,
That changed the width of the combo box. I need to change the height so that it shows more records at a time.

thanks,
kcorrigan
 
Correction: When I used the exact code you provided, I didn't get any changes. But when I used this:

form1.scalemode = vbpixels
combo1.width = 750

...I got the larger width so that was my mistake. I tried:
combo1.height = 750,
But it says height is a read-only property. What did I do wrong with your original code that might fix this?
 
I suggest that you use the code as given, rather than trying to change it to what you think it ought to be. You CANNOT directly change combo1.height as you seem to be attempting.
 
I originally did use the code as given, which is how I have restored it now. But nothing happens. That's the only reason I was trying other solutions, because what you originally posted did not work for me. Are you using any special references or anything? It just is not changing the height value for my combo box. Thanks!
 
The code comes more-or-less directly from a working program. As it stands it works Ok on my NT box, my W98 box, and on my W2000 box. All using VB6 SP5.

Tell me, how many items have you got in the combobox that you are testing this on?
 
It depends on what data is being loaded each time. For the test sample I'm using the most, it has been 25 items.
 
Ok, let's confirm:

a) Your OS
b) version of VB
c) that combo1 contains 25 items (or more than 8, at any rate) whilst testing this code
 
W2000, VB6.0, and yes there are more than 8 items in the box
 
Well, can't tell you why it isn't working then. As I say, it works fine here (which isn't a lot of comfort to you, I know) Anyone else want to try the code AS POSTED, and confirm whether it works for them or not.
 


Let's confirm one more thing:

1. Is this a ComboBox, or a DataCombo (OLEDB)?

Adding the code in the Combo1_DropDown event of a normal Combo box will work.

But, not for a DataCombo.
[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
strongm

Just tested it, on W2k, base VB6 (i.e. no SP!)

and it works fine

Nice tip!

Matt
 

Combo box or DataCombo? [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top