Results 1 to 3 of 3

Thread: Listbox enabled and scrolling

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    San Diego - California
    Posts
    251

    Listbox enabled and scrolling

    I have a multiselection listbox with a number of checkbox styled items. I would like the use to be able to stroll through the list but not change the selection. - (Type of Access Control) -

    Setting the Enabled property to false prevents the user scrolling as well as the input.

    Is there a simple way to prevent selection changes but allow scrolling.

    Ant help would be appreciated.

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Location
    The Lone Star State
    Posts
    183
    Option Explicit
    Private Beenhere As Boolean

    Private Sub Form_Load()

    With Me.List1
    .AddItem "Item 1"
    .AddItem "Item 2"
    .AddItem "Item 3"
    Beenhere = True
    .Selected(1) = True
    End With

    End Sub

    Private Sub List1_Click()

    Beenhere = False

    End Sub

    Private Sub List1_ItemCheck(Item As Integer)

    If Not Beenhere Then
    Me.List1.Selected(Item) = Not Me.List1.Selected(Item)
    Beenhere = True
    End If

    End Sub
    !

  3. #3
    Matthew Gates
    Guest
    You can subclass the Listbox, intercept the WM_LBUTTONDOWN message and disable it.


    Code:
    'Module code:
    
    Declare Function GetWindowLong Lib "user32" _
    Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal _
    nIndex As Long) As Long
    
    Declare Function SetWindowLong& Lib "user32" _
    Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal _
    nIndex As Long, ByVal dwNewLong As Long)
    
    Declare Function CallWindowProc Lib "user32" _
    Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
    ByVal hwnd As Long, ByVal msg As Long, ByVal wParam _
    As Long, ByVal lParam As Long) As Long
    
    Const GWL_WNDPROC = (-4)
    Const WM_LBUTTONDOWN = &H201
    
    Public WndProcOld As Long
    
    Public Function WindProc(ByVal hwnd As Long, ByVal _
    wMsg As Long, ByVal wParam As Long, ByVal lParam As _
    Long) As Long
        If wMsg = WM_LBUTTONDOWN Then Exit Function
        WindProc = CallWindowProc(WndProcOld&, hwnd&, _
        wMsg&, wParam&, lParam&)
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WndProcOld& = SetWindowLong(hwnd, _
        GWL_WNDPROC, AddressOf WindProc)
    End Sub
    
    Sub UnSubClassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
        WndProcOld& = 0
    End Sub
    
    
    
    'Form code:
    
    
    Private Sub Form_Load()
        SubClassWnd List1.hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubClassWnd List1.hwnd
    End Sub

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