Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 340065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:34:53+00:00 2026-05-12T10:34:53+00:00

I cannot get the DropDownHeight of the ComboBox set properly to display all the

  • 0

I cannot get the DropDownHeight of the ComboBox set properly to display all the items.

I am using a control that inherits from the ComboBox. I have overridden the OnDrawItem and OnMeasureItem methods in order to create multiple columns and text-wrapping within a column if it is required. This all works fine.

The problem occurs when I try to set the DropDownHeight. I set the DropDownHeight at an arbitrarily large value, a good bit larger than the list of items. The ComboBox control appears to automatically truncate any value for DropDownHeight that is larger than the size of all the displayed items in the list. (Assuming that you have the MaxDropDownItems property set higher than the number of items, which I do.) Normally this behavior works perfectly, as shown below:
alt text http://www.freeimagehosting.net/uploads/dd09404697.png

No, that’s not my real data in the drop-down box.

The problem occurs when I have an entry in the drop-down that needs to wrap in order to display the full text. This entry displays fine, but however the ComboBox is calculating the DropDownHeight, it ignores the fact that one of the entries is twice as tall as normal, so you have to scroll down one line to get to the last entry in the drop-down.
alt text http://www.freeimagehosting.net/uploads/d0ef715f83.png

This is the code that I am using to determine if an item needs text wrapping and to set the height of each item:

 Protected Overrides Sub OnMeasureItem(ByVal e As System.Windows.Forms.MeasureItemEventArgs)
    MyBase.OnMeasureItem(e)
    //Determine the proper height of the current row in the dropdown based on
    //the length of the OptionDescription string.
    Dim tmpStr As String = FilterItemOnProperty(Items(e.Index), "OptionDescription")
    Dim lng As Single = e.Graphics.MeasureString(tmpStr, Me.Font).Width
    //Use the length of the item and the width of the column to calculate if wrapping is needed.
    Dim HeightMultiplier As Integer = Math.Floor(lng / _ColumnWidths(1)) + 1
    e.ItemHeight = e.ItemHeight * HeightMultiplier

 End Sub

I cannot determine how to force the DropDownHeight property to be exactly the value that I want, or how to let the ComboBox control know that one (or more) of the items in the list are taller than normal.

I’ve tried to Override Shadow the DropDownHeight property, but this seemed to have no impact.

EDIT:
Would switching to WPF make this problem go away? (Is there enough customizability in the standard WPF controls so that I don’t need to write a custom control for a 3-column, variable-height combobox?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:34:54+00:00Added an answer on May 12, 2026 at 10:34 am

    I’m trying to solve this exact same problem myself right at the moment for an application that I am migrating from VB6 to VB.NET. The owner-drawn combo control I have in VB6 sets the height of the drop-down through a SetWindowPos API call in response to the WM_CTLCOLORLISTBOX message on the combo control, which gives us access to the HWnd for the drop-down list of the combo control. The following code was added to my class that inherits from ComboBox and seems to do the trick, but still needs testing. I’m not sure it’s the most elegant way of doing this either. Obviously you’ll need to change the line that sets the newHeight variable, but this should give you the general idea.

    Private Structure RECT
        Public Left As Integer        'x position Of upper-left corner
        Public Top As Integer         'y position Of upper-left corner
        Public Right As Integer       'x position Of lower-right corner
        Public Bottom As Integer      'y position Of lower-right corner
    End Structure
    
    Private Declare Function GetWindowRect Lib "user32" _
            (ByVal hwnd As Integer, ByRef lpRect As RECT) As Integer
    
    Private Declare Sub SetWindowPos Lib "user32" _
            (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, _
            ByVal X As Integer, ByVal Y As Integer, _
            ByVal cx As Integer, ByVal cy As Integer, _
            ByVal wFlags As Integer)
    
    Private Const SWP_NOZORDER As Integer = &H4
    Private Const SWP_NOACTIVATE As Integer = &H10
    Private Const SWP_FRAMECHANGED As Integer = &H20
    Private Const SWP_NOOWNERZORDER As Integer = &H200
    
    Private _hwndDropDown As Integer = 0
    
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Const WM_CTLCOLORLISTBOX As Integer = &H134
    
        If m.Msg = WM_CTLCOLORLISTBOX Then
            If _hwndDropDown = 0 Then
                _hwndDropDown = m.LParam.ToInt32
    
                Dim r As RECT
                GetWindowRect(m.LParam.ToInt32, r)
    
                'height of four items plus 2 pixels for the border in my test
                Dim newHeight As Integer = 4 * MyBase.ItemHeight + 2
    
                SetWindowPos(m.LParam.ToInt32, 0, _
                             r.Left, _
                             r.Top, _
                             MyBase.DropDownWidth, _
                             newHeight, _
                             SWP_FRAMECHANGED Or _
                                    SWP_NOACTIVATE Or _
                                    SWP_NOZORDER Or _
                                    SWP_NOOWNERZORDER)
            End If
        End If
    
        MyBase.WndProc(m)
    End Sub
    
    Protected Overrides Sub OnDropDownClosed(ByVal e As System.EventArgs)
        _hwndDropDown = 0
        MyBase.OnDropDownClosed(e)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot get IDataErrorInfo to validate reference properties that have [Required] attribute set to
I cannot get Google Maps to display for the life of me. I have
I cannot get the style width value to display correctly when using inline syntax.
I cannot get a form to submit additional fields that have been cloned. When
I cannot get the returning data from the server to display on my form
I cannot get my Spring web app to find my scripts. I have the
I cannot get the following route to fire when a url is requested from
I cannot get the Theme.Dialog activity to get smaller. The problem is that i
I cannot get my Canon Pixma MP150 to scan a color scan from c#
I cannot get this last div to go up properly in my layout and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.