CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: ComboBox

  1. #1
    Guest

    ComboBox

    Hi
    I have a combobox control, the width of it is not enough to display the item string, but there is no more space in the form. Does anybody know how to display the data completely when the list shows?
    Thanks a lot for any help.


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: ComboBox

    This should do the trick, I've been using it for a few years with no problems :

    http://www.mvps.org/vbnet/code/listapi/combowidth.htm




    Chris Eastwood

    CodeGuru - the website for developers
    http://www.codeguru.com/vb

  3. #3
    Join Date
    Jul 1999
    Posts
    7

    Re: ComboBox

    Private Const CB_GETDROPPEDWIDTH = &H15F
    Private Const CB_SETDROPPEDWIDTH = &H160
    Private Const CB_ERR = -1

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    ------------------------------------------
    In the form load call

    Call SetDropdownWidth(ComboBox.hwnd,GetDropdownWidth(ComboBox.hwnd) * 1.5)

    1.5 means drop down width becomes one and half times the actual one.

    Public Function GetDropdownWidth(cboHwnd As Long) As Long

    Dim lRetVal As Long

    '*** To get the combo box drop-down width.

    '*** You may use this function if you want

    '*** to change the width in proportion

    '*** i.e. double, half, 3/4 of existing width.

    lRetVal = SendMessage(cboHwnd, CB_GETDROPPEDWIDTH, 0, 0)

    If lRetVal <> CB_ERR Then

    GetDropdownWidth = lRetVal

    'Width in pixels

    Else

    GetDropdownWidth = 0

    End If

    End Function

    Public Function SetDropdownWidth(cboHwnd As Long, NewWidthPixel As Long) As Boolean

    Dim lRetVal As Long

    ' *** To set combo box drop-down width ***

    lRetVal = SendMessage(cboHwnd, CB_SETDROPPEDWIDTH, NewWidthPixel, 0)

    If lRetVal <> CB_ERR Then

    SetDropdownWidth = True

    Else

    SetDropdownWidth = False

    End If

    End Function


    Santosh N
    Sr. Software Engineer,
    Wipro Infotech, India.

  4. #4
    Guest

    Re: ComboBox

    Thanks a lot.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured