473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ComboBox

I have a ComboBox (style 2) with 25 items in it. When I click on the arrow
to see the items, I can only see the first 8. I have to scroll to see the
others. Is there some way so set how many items will be visible when the
menu drops down to eliminate/reduce the scrolling?

Regards,
Tom

Jul 17 '05 #1
7 3548
On Fri, 14 May 2004 07:35:44 GMT, "Kiteman - Canada"
<-d*************@shaw.ca> wrote:
I have a ComboBox (style 2) with 25 items in it. When I click on the arrow
to see the items, I can only see the first 8. I have to scroll to see the
others. Is there some way so set how many items will be visible when the
menu drops down to eliminate/reduce the scrolling?


This is Rick Rothstein's example

It is extremely comprehensive.

' 29/6/03 Rick Rothstein

' Sets height of Simple Combo

Option Explicit: DefObj A-Z
Private Declare Function SendMessageLong Lib "user32" _
Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Private Declare Function GetWindowRect Lib "user32" ( _
ByVal hWnd As Long, _
lpRect As RECT) As Long

Private Declare Function ScreenToClient Lib "user32" ( _
ByVal hWnd As Long, _
lpPoint As POINTAPI) As Long

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 Const CB_GETITEMHEIGHT = &H154

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Sub Form_Load()
Dim L9%

For L9 = 1 To 100
Combo1.AddItem "Item" + Str(L9)
Next

End Sub
Private Sub Command1_Click()
Call SetComboBoxHeight(Combo1, Val(Text1.Text))
End Sub
Public Sub SetComboBoxHeight( _
ComboBoxIn As ComboBox, _
NumberOfItemsTall As Long)
Dim Point As POINTAPI
Dim Rectangle As RECT
Dim ComboBoxWidth As Long
Dim NewComboBoxHeight As Long
Dim EditAreaHeight As Long
Dim ListAreaHeight As Long

ComboBoxWidth = ComboBoxIn.Width \ Screen.TwipsPerPixelX
ListAreaHeight = SendMessageLong( _
ComboBoxIn.hWnd, _
CB_GETITEMHEIGHT, 0, 0)
EditAreaHeight = SendMessageLong( _
ComboBoxIn.hWnd, _
CB_GETITEMHEIGHT, -1, 0)
NewComboBoxHeight = _
ListAreaHeight * NumberOfItemsTall + _
2 * EditAreaHeight
GetWindowRect ComboBoxIn.hWnd, Rectangle
Point.X = Rectangle.Left
Point.Y = Rectangle.Top
ScreenToClient ComboBoxIn.Container.hWnd, Point
MoveWindow ComboBoxIn.hWnd, _
Point.X, Point.Y, _
ComboBoxWidth, NewComboBoxHeight, True
End Sub
Jul 17 '05 #2
> >I have a ComboBox (style 2) with 25 items in it. When I click on
the arrow
to see the items, I can only see the first 8. I have to scroll to see theothers. Is there some way so set how many items will be visible when themenu drops down to eliminate/reduce the scrolling?


This is Rick Rothstein's example

It is extremely comprehensive.

' 29/6/03 Rick Rothstein


Are you sure that is mine? I can't see myself having used

Option Explicit: DefObj A-Z

or

Dim L9%

in my postings. Also, you don't have to credit me with this solution;
I'm pretty sure I stole it from someone else.<g> (Actually, I probably
modified someone else's code to cobble it together, but that is nearly
the same thing.)

Rick

Jul 17 '05 #3
Thanks very much J French for the "allegedly" Rick Rothstein snippet. It
worked like a charm.
Took me a while to figure out what parts were mandatory and what names I had
to change to get it to work with my ComboBox name, but it works like a
charm.

Pardon another question....by using this bit of code, does it require any
supporting files (such as DLLs) to be installed on the users system when
they run my .exe?

Tom

"J French" <er*****@nowhere.com> wrote in message
news:40***************@news.btclick.com...
On Fri, 14 May 2004 07:35:44 GMT, "Kiteman - Canada"
<-d*************@shaw.ca> wrote:
I have a ComboBox (style 2) with 25 items in it. When I click on the arrowto see the items, I can only see the first 8. I have to scroll to see theothers. Is there some way so set how many items will be visible when themenu drops down to eliminate/reduce the scrolling?


This is Rick Rothstein's example

It is extremely comprehensive.

' 29/6/03 Rick Rothstein

' Sets height of Simple Combo

Option Explicit: DefObj A-Z
Private Declare Function SendMessageLong Lib "user32" _
Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Private Declare Function GetWindowRect Lib "user32" ( _
ByVal hWnd As Long, _
lpRect As RECT) As Long

Private Declare Function ScreenToClient Lib "user32" ( _
ByVal hWnd As Long, _
lpPoint As POINTAPI) As Long

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 Const CB_GETITEMHEIGHT = &H154

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Sub Form_Load()
Dim L9%

For L9 = 1 To 100
Combo1.AddItem "Item" + Str(L9)
Next

End Sub
Private Sub Command1_Click()
Call SetComboBoxHeight(Combo1, Val(Text1.Text))
End Sub
Public Sub SetComboBoxHeight( _
ComboBoxIn As ComboBox, _
NumberOfItemsTall As Long)
Dim Point As POINTAPI
Dim Rectangle As RECT
Dim ComboBoxWidth As Long
Dim NewComboBoxHeight As Long
Dim EditAreaHeight As Long
Dim ListAreaHeight As Long

ComboBoxWidth = ComboBoxIn.Width \ Screen.TwipsPerPixelX
ListAreaHeight = SendMessageLong( _
ComboBoxIn.hWnd, _
CB_GETITEMHEIGHT, 0, 0)
EditAreaHeight = SendMessageLong( _
ComboBoxIn.hWnd, _
CB_GETITEMHEIGHT, -1, 0)
NewComboBoxHeight = _
ListAreaHeight * NumberOfItemsTall + _
2 * EditAreaHeight
GetWindowRect ComboBoxIn.hWnd, Rectangle
Point.X = Rectangle.Left
Point.Y = Rectangle.Top
ScreenToClient ComboBoxIn.Container.hWnd, Point
MoveWindow ComboBoxIn.hWnd, _
Point.X, Point.Y, _
ComboBoxWidth, NewComboBoxHeight, True
End Sub

Jul 17 '05 #4
> Pardon another question....by using this bit of code, does it require
any
supporting files (such as DLLs) to be installed on the users system when they run my .exe?


Technically, yes, it requires DLL's, but no, you don't have to install
any of them. The API functions all call DLL's that were installed along
with Windows when it was installed, so they are automatically available
for use.

Rick

Jul 17 '05 #5
Thanks very much Rick.

I get enough users asking how to find msstdfmt.dll and I didn't want make
things worse for the users if I did not have to.

Tom

"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:9v********************@comcast.com...
Pardon another question....by using this bit of code, does it require

any
supporting files (such as DLLs) to be installed on the users system

when
they run my .exe?


Technically, yes, it requires DLL's, but no, you don't have to install
any of them. The API functions all call DLL's that were installed along
with Windows when it was installed, so they are automatically available
for use.

Rick

Jul 17 '05 #6
Here's the (a) explanation ...
http://vbnet.mvps.org/code/comboapi/comboheight.htm

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Kiteman - Canada" <-d*************@shaw.ca> wrote in message
news:tu9pc.477359$oR5.284826@pd7tw3no...
: Thanks very much J French for the "allegedly" Rick Rothstein snippet. It
: worked like a charm.
: Took me a while to figure out what parts were mandatory and what names I
had
: to change to get it to work with my ComboBox name, but it works like a
: charm.
:
: Pardon another question....by using this bit of code, does it require any
: supporting files (such as DLLs) to be installed on the users system when
: they run my .exe?
:
: Tom
:
: "J French" <er*****@nowhere.com> wrote in message
: news:40***************@news.btclick.com...
: > On Fri, 14 May 2004 07:35:44 GMT, "Kiteman - Canada"
: > <-d*************@shaw.ca> wrote:
: >
: > >I have a ComboBox (style 2) with 25 items in it. When I click on the
: arrow
: > >to see the items, I can only see the first 8. I have to scroll to see
: the
: > >others. Is there some way so set how many items will be visible when
: the
: > >menu drops down to eliminate/reduce the scrolling?
: > >
: >
: > This is Rick Rothstein's example
: >
: > It is extremely comprehensive.
: >
: > ' 29/6/03 Rick Rothstein
: >
: > ' Sets height of Simple Combo
: >
: > Option Explicit: DefObj A-Z
: >
: >
: > Private Declare Function SendMessageLong Lib "user32" _
: > Alias "SendMessageA" ( _
: > ByVal hWnd As Long, _
: > ByVal wMsg As Long, _
: > ByVal wParam As Long, _
: > ByVal lParam As Long) As Long
: >
: > Private Declare Function GetWindowRect Lib "user32" ( _
: > ByVal hWnd As Long, _
: > lpRect As RECT) As Long
: >
: > Private Declare Function ScreenToClient Lib "user32" ( _
: > ByVal hWnd As Long, _
: > lpPoint As POINTAPI) As Long
: >
: > 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 Const CB_GETITEMHEIGHT = &H154
: >
: > Private Type RECT
: > Left As Long
: > Top As Long
: > Right As Long
: > Bottom As Long
: > End Type
: >
: > Private Type POINTAPI
: > X As Long
: > Y As Long
: > End Type
: >
: > Private Sub Form_Load()
: > Dim L9%
: >
: > For L9 = 1 To 100
: > Combo1.AddItem "Item" + Str(L9)
: > Next
: >
: > End Sub
: >
: >
: > Private Sub Command1_Click()
: > Call SetComboBoxHeight(Combo1, Val(Text1.Text))
: > End Sub
: >
: >
: > Public Sub SetComboBoxHeight( _
: > ComboBoxIn As ComboBox, _
: > NumberOfItemsTall As Long)
: > Dim Point As POINTAPI
: > Dim Rectangle As RECT
: > Dim ComboBoxWidth As Long
: > Dim NewComboBoxHeight As Long
: > Dim EditAreaHeight As Long
: > Dim ListAreaHeight As Long
: >
: > ComboBoxWidth = ComboBoxIn.Width \ Screen.TwipsPerPixelX
: > ListAreaHeight = SendMessageLong( _
: > ComboBoxIn.hWnd, _
: > CB_GETITEMHEIGHT, 0, 0)
: > EditAreaHeight = SendMessageLong( _
: > ComboBoxIn.hWnd, _
: > CB_GETITEMHEIGHT, -1, 0)
: > NewComboBoxHeight = _
: > ListAreaHeight * NumberOfItemsTall + _
: > 2 * EditAreaHeight
: > GetWindowRect ComboBoxIn.hWnd, Rectangle
: > Point.X = Rectangle.Left
: > Point.Y = Rectangle.Top
: > ScreenToClient ComboBoxIn.Container.hWnd, Point
: > MoveWindow ComboBoxIn.hWnd, _
: > Point.X, Point.Y, _
: > ComboBoxWidth, NewComboBoxHeight, True
: > End Sub
: >
: >
:
:

Jul 17 '05 #7
On Fri, 14 May 2004 12:47:09 -0400, "Rick Rothstein"
<ri************@NOSPAMcomcast.net> wrote:

<snip>
' 29/6/03 Rick Rothstein


Are you sure that is mine? I can't see myself having used

Option Explicit: DefObj A-Z

or

Dim L9%

in my postings. Also, you don't have to credit me with this solution;
I'm pretty sure I stole it from someone else.<g> (Actually, I probably
modified someone else's code to cobble it together, but that is nearly
the same thing.)


It is yours, I just added populating the Combo
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Mr. B | last post by:
Here's the situation... You've a combobox with Items already added. Say they look like this (or even lines of text): 10-00-232 10-00-256 10-01-006 10-01-213 10-02-200
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
8
by: Zlatko Matię | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new...
3
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article:...
2
by: Don | last post by:
I've looked high and low for some code that will allow me to have a combobox with a flat borderstyle. I found a few examples, but nothing that was really usable for me. I had the following...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
1
by: polocar | last post by:
Ciao a tutti, leggendo qua e lą per il forum ho scoperto che non sono l'unico ad avere questo problema. Se si inserisce un controllo ComboBox in un form di C#, non č possibile impostare la sua...
5
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.