The text in the Combo box has lenthly text, but combo box has no horizondal scroll bar. I want to Add Horizondal Scroll bar to Combo Box.

Advanced Thanks
Raghuraja

In a standard code module, add this:

Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const GWL_STYLE = (-16)
Public Const WS_HSCROLL = &H100000

Then in your form load (or whatever) add this:

Dim lWindowStyle As Long
lWindowStyle = GetWindowLong(combo1.hwnd, GWL_STYLE)
lWindowStyle = lWindowStyle Or WS_HSCROLL
lWindowStyle = SetWindowLong(combo1.hwnd, GWL_STYLE, lWindowStyle)

That should work. Let me know how it turns out.

I have added this code, but still the "Horizondal Scroll Bar" is not appearing ...

Other than this code, any setting need to add?

Please review the following code and give your feedback.
I am using this code

Option Explicit

Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Const GWL_STYLE As Long = (-16)
Const WS_HSCROLL As Long = &H100000

Private Sub Form_Load()

Dim lWindowStyle As Long
lWindowStyle = GetWindowLong(Combo1.hwnd, GWL_STYLE)
lWindowStyle = lWindowStyle Or WS_HSCROLL
lWindowStyle = SetWindowLong(Combo1.hwnd, GWL_STYLE, lWindowStyle)

Combo1.Width = 2895

Combo1.AddItem "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
Combo1.AddItem "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
Combo1.AddItem "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
Combo1.AddItem "DDDDDDDDDDDDDDDDDDDDDDDDD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UUUUUUUUUUUUUUUUUUUU"
Combo1.AddItem "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
Combo1.AddItem "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW"
Combo1.AddItem "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Combo1.AddItem "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"
Combo1.AddItem "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"

End Sub

This article has been dead for over six months. Start a new discussion instead.