ComboBox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kiteman - Canada

    #1

    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



  • J French

    #2
    Re: ComboBox

    On Fri, 14 May 2004 07:35:44 GMT, "Kiteman - Canada"
    <-delete-kiteman@shaw.ca > wrote:
    [color=blue]
    >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?
    >[/color]

    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 "SendMessag eA" ( _
    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_GETITEMHEIGH T = &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 SetComboBoxHeig ht(Combo1, Val(Text1.Text) )
    End Sub


    Public Sub SetComboBoxHeig ht( _
    ComboBoxIn As ComboBox, _
    NumberOfItemsTa ll As Long)
    Dim Point As POINTAPI
    Dim Rectangle As RECT
    Dim ComboBoxWidth As Long
    Dim NewComboBoxHeig ht As Long
    Dim EditAreaHeight As Long
    Dim ListAreaHeight As Long

    ComboBoxWidth = ComboBoxIn.Widt h \ Screen.TwipsPer PixelX
    ListAreaHeight = SendMessageLong ( _
    ComboBoxIn.hWnd , _
    CB_GETITEMHEIGH T, 0, 0)
    EditAreaHeight = SendMessageLong ( _
    ComboBoxIn.hWnd , _
    CB_GETITEMHEIGH T, -1, 0)
    NewComboBoxHeig ht = _
    ListAreaHeight * NumberOfItemsTa ll + _
    2 * EditAreaHeight
    GetWindowRect ComboBoxIn.hWnd , Rectangle
    Point.X = Rectangle.Left
    Point.Y = Rectangle.Top
    ScreenToClient ComboBoxIn.Cont ainer.hWnd, Point
    MoveWindow ComboBoxIn.hWnd , _
    Point.X, Point.Y, _
    ComboBoxWidth, NewComboBoxHeig ht, True
    End Sub


    Comment

    • Rick Rothstein

      #3
      Re: ComboBox

      > >I have a ComboBox (style 2) with 25 items in it. When I click on
      the arrow[color=blue][color=green]
      > >to see the items, I can only see the first 8. I have to scroll to[/color][/color]
      see the[color=blue][color=green]
      > >others. Is there some way so set how many items will be visible[/color][/color]
      when the[color=blue][color=green]
      > >menu drops down to eliminate/reduce the scrolling?
      > >[/color]
      >
      > This is Rick Rothstein's example
      >
      > It is extremely comprehensive.
      >
      > ' 29/6/03 Rick Rothstein[/color]

      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

      Comment

      • Kiteman - Canada

        #4
        Re: ComboBox

        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" <erewhon@nowher e.com> wrote in message
        news:40a49caf.1 3269611@news.bt click.com...[color=blue]
        > On Fri, 14 May 2004 07:35:44 GMT, "Kiteman - Canada"
        > <-delete-kiteman@shaw.ca > wrote:
        >[color=green]
        > >I have a ComboBox (style 2) with 25 items in it. When I click on the[/color][/color]
        arrow[color=blue][color=green]
        > >to see the items, I can only see the first 8. I have to scroll to see[/color][/color]
        the[color=blue][color=green]
        > >others. Is there some way so set how many items will be visible when[/color][/color]
        the[color=blue][color=green]
        > >menu drops down to eliminate/reduce the scrolling?
        > >[/color]
        >
        > 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 "SendMessag eA" ( _
        > 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_GETITEMHEIGH T = &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 SetComboBoxHeig ht(Combo1, Val(Text1.Text) )
        > End Sub
        >
        >
        > Public Sub SetComboBoxHeig ht( _
        > ComboBoxIn As ComboBox, _
        > NumberOfItemsTa ll As Long)
        > Dim Point As POINTAPI
        > Dim Rectangle As RECT
        > Dim ComboBoxWidth As Long
        > Dim NewComboBoxHeig ht As Long
        > Dim EditAreaHeight As Long
        > Dim ListAreaHeight As Long
        >
        > ComboBoxWidth = ComboBoxIn.Widt h \ Screen.TwipsPer PixelX
        > ListAreaHeight = SendMessageLong ( _
        > ComboBoxIn.hWnd , _
        > CB_GETITEMHEIGH T, 0, 0)
        > EditAreaHeight = SendMessageLong ( _
        > ComboBoxIn.hWnd , _
        > CB_GETITEMHEIGH T, -1, 0)
        > NewComboBoxHeig ht = _
        > ListAreaHeight * NumberOfItemsTa ll + _
        > 2 * EditAreaHeight
        > GetWindowRect ComboBoxIn.hWnd , Rectangle
        > Point.X = Rectangle.Left
        > Point.Y = Rectangle.Top
        > ScreenToClient ComboBoxIn.Cont ainer.hWnd, Point
        > MoveWindow ComboBoxIn.hWnd , _
        > Point.X, Point.Y, _
        > ComboBoxWidth, NewComboBoxHeig ht, True
        > End Sub
        >
        >[/color]


        Comment

        • Rick Rothstein

          #5
          Re: ComboBox

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

          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

          Comment

          • Kiteman - Canada

            #6
            Re: ComboBox

            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" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message
            news:9vWdnSLIPM KasDjdRVn-tw@comcast.com. ..[color=blue][color=green]
            > > Pardon another question....by using this bit of code, does it require[/color]
            > any[color=green]
            > > supporting files (such as DLLs) to be installed on the users system[/color]
            > when[color=green]
            > > they run my .exe?[/color]
            >
            > 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
            >[/color]


            Comment

            • Randy Birch

              #7
              Re: ComboBox

              Here's the (a) explanation ...
              VBnet provides Intermediate and Advanced Win32 API code for VB developers. Comprehensive Code, FAQ, Developers Resources & News, alphabetical API/Type/Constant/Method Index, along with the largest Visual Basic-related links list on the net.


              --

              Randy Birch
              MVP Visual Basic

              Please respond only to the newsgroups so all can benefit.


              "Kiteman - Canada" <-delete-kiteman@shaw.ca > wrote in message
              news:tu9pc.4773 59$oR5.284826@p d7tw3no...
              : 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" <erewhon@nowher e.com> wrote in message
              : news:40a49caf.1 3269611@news.bt click.com...
              : > On Fri, 14 May 2004 07:35:44 GMT, "Kiteman - Canada"
              : > <-delete-kiteman@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 "SendMessag eA" ( _
              : > 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_GETITEMHEIGH T = &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 SetComboBoxHeig ht(Combo1, Val(Text1.Text) )
              : > End Sub
              : >
              : >
              : > Public Sub SetComboBoxHeig ht( _
              : > ComboBoxIn As ComboBox, _
              : > NumberOfItemsTa ll As Long)
              : > Dim Point As POINTAPI
              : > Dim Rectangle As RECT
              : > Dim ComboBoxWidth As Long
              : > Dim NewComboBoxHeig ht As Long
              : > Dim EditAreaHeight As Long
              : > Dim ListAreaHeight As Long
              : >
              : > ComboBoxWidth = ComboBoxIn.Widt h \ Screen.TwipsPer PixelX
              : > ListAreaHeight = SendMessageLong ( _
              : > ComboBoxIn.hWnd , _
              : > CB_GETITEMHEIGH T, 0, 0)
              : > EditAreaHeight = SendMessageLong ( _
              : > ComboBoxIn.hWnd , _
              : > CB_GETITEMHEIGH T, -1, 0)
              : > NewComboBoxHeig ht = _
              : > ListAreaHeight * NumberOfItemsTa ll + _
              : > 2 * EditAreaHeight
              : > GetWindowRect ComboBoxIn.hWnd , Rectangle
              : > Point.X = Rectangle.Left
              : > Point.Y = Rectangle.Top
              : > ScreenToClient ComboBoxIn.Cont ainer.hWnd, Point
              : > MoveWindow ComboBoxIn.hWnd , _
              : > Point.X, Point.Y, _
              : > ComboBoxWidth, NewComboBoxHeig ht, True
              : > End Sub
              : >
              : >
              :
              :

              Comment

              • J French

                #8
                Re: ComboBox

                On Fri, 14 May 2004 12:47:09 -0400, "Rick Rothstein"
                <rickNOSPAMnews @NOSPAMcomcast. net> wrote:

                <snip>[color=blue][color=green]
                >> ' 29/6/03 Rick Rothstein[/color]
                >
                >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.)[/color]

                It is yours, I just added populating the Combo

                Comment

                Working...