Results 1 to 3 of 3

Thread: list box control in visual basic 5

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    2

    Post

    Dear friends,

    I design a list box control with five items.

    As the list box is too short to display all the items during the run time, vb5 automatically places a vertical scroll bar on the right side of the list box.

    Then user can scroll to see the remaining items of the list and select it by clicking on it with the mouse.

    As I know we can also highlight an item and select it, from a list by moving to it with the up- and down- arrow keys, the highlight will move according to the arrow keys.

    so, using visual basic 5, can I design the same things by just scroll the top and bottom arrow button of the vertical scroll bar on the right side of the list box control and causing the highlight and selected item move accordingly, instead of using up- and down arrow keys.

    This type of control is also appear on Microsoft Internet Explorer5.

    When you select the 'Tools' in the menu bar and click on Internet Options, a form will be pop up with 'multi-page control', that is General, Security, Content, Connections, Programs and Advanced. Please click the 'General' page and you will find a list box control on the history 'frame control'.

    Please click on the top and bottom arrow button of the vertical scroll bar on the right side of the list box control. You will found the highlight and selected item move accordingly. This is the design I wish to produced.

    I hope that these description will help you to answer my question.

    I really appreciate it with your help. Have a nice day. Thanks a lot.

    Warmest regards,
    Lai

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    Add a Combobox with Style = 1 - Simple Combo, Height = 315
    Add a Vertical Scrollbar with Height = 315 adjacent to your Combobox.
    Then you can use the following:
    Code:
    Option Explicit
    
    Private Sub Combo1_KeyPress(KeyAscii As Integer)
        'Disallow User Typing
        KeyAscii = 0
    End Sub
    
    Private Sub Form_Load()
    Dim bCounter As Byte
    
        'Prep Combo, Select First Item, Highlight Selection
        With Combo1
            'Set Next 2 Properties in Properties - Can't assign at run-time
            '.Style = vbComboSimple
            '.Height = 315
            
            For bCounter = 1 To 10
                .AddItem bCounter
            Next bCounter
            
            .ListIndex = 0
            .Text = .List(.ListIndex)
            .SelStart = 0
            .SelLength = Len(.Text)
        End With
        
        'Prep Vertical ScrollBar, Store Combo Selection
        With VScroll1
            .Height = 315
            .Min = 0
            .Max = Combo1.ListCount - 1
            .Value = 0
            .Tag = Combo1.ListIndex
        End With
    End Sub
    
    Private Sub VScroll1_Change()
        With Combo1
            'Up 1 from Last Selection, Increment
            If VScroll1.Value > VScroll1.Tag Then
                .ListIndex = .ListIndex + 1
            End If
            
            'Down 1 from Last Selection, Decrement
            If VScroll1.Value < VScroll1.Tag Then
                Combo1.ListIndex = Combo1.ListIndex - 1
            End If
                            
            'Highlight User Selection
            .Text = .List(.ListIndex)
            .SelStart = 0
            .SelLength = Len(.Text)
            .SetFocus
            
            'Store Combo Selection
            VScroll1.Tag = Combo1.ListIndex
        End With
    End Sub
    
    Private Sub VScroll1_GotFocus()
        'Highlight User Selection (or Default)
        With Combo1
            .Text = .List(.ListIndex)
            .SelStart = 0
            .SelLength = Len(.Text)
            .SetFocus
        End With
    End Sub
    Wade

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    2

    Thanks a lot.....:-).....It's work.

    Dear WadeD,

    Thank you!!!!! It's work now!

    Have a nice day!

    Best Regards,

    lai

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