Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox mouse click X and Y pos 1

Status
Not open for further replies.

eatwork

Technical User
May 16, 2005
155
CA
Hi,
I was wondering if anyone could tell me how I can determine the x position in a listbox if the user has used the horizontal scroll bar and scrolled over to the right? thank you
 
How are ya eatwork . . .

In VBE help, have a look at the [blue]ListIndex[/blue] property . . .

Calvin.gif
See Ya! . . . . . .
 
Hi TheAceMan1,
Thank you for the post, doin alright. yourself?
I looked up listindex and I think I may not have been clear on what I was looking for.
I have a listbox, which has 15 columns. These columns do not fit on the user screen. The listbox has a horizontal scroll bar and the users can scroll to view the columns that are not able to fit in the screen display.
What I am looking for is the x(horizontal) position of the scroll bar, or the x-position of where the user has clicked into the listbox. I am able to find the position of the mouse in the listbox when the user clicks into the listbox without scrolling to the right, but cannot seem to calculate or return the position of the mouse when the user clicks into a scrolled listbox. Thank you
 
eatwork . . .

Since [blue]you can only select an entire record[/blue] . . . whats the point?

Calvin.gif
See Ya! . . . . . .
 
Hello TheAceMan
I need to figure out the position of the mouse cursor + the amount scrolled because I was able to stumble across some code that allows the user to sort listbox columns, but it doesn't work when the horizontal scrollbar is moved. I was able to analyse the code and discovered the only reason it doesn't work is because he doesn't return the the amount scrolled + the x position of the mouse when clicked. Thanks
 
eatwork . . .

Can't be done with access alone! Perhaps [blue]with the assistance of an [purple]API[/purple] or two[/blue], but I've never heard of an [purple]API[/purple] that can track listbox scroll bars!

In either case, [purple]API[/purple] is advanced programming and not for the light of heart.

What you can do is [blue]use a subform instead[/blue] (you can make a subform look just like a listbox!) and use the [blue]On Click[/blue] event of the controls to trigger your sorting code!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks TheAceMan1,
I am trying to look for the API version online. I have found API's that return the horizontal scroll bar for forms, but I can't get it converted to a listbox control. The code is from Stephen Lebans. the code below returns the scroll for a form, is there anyway to convert this to return the values for a listbox? Thank you

Code:
Private Function fIsScrollBarHZ(frm As Form) As Long
' Get ScrollBar's Horizontal hWnd
Dim hWnd_VSB As Long
Dim hWnd As Long
Dim lngStyle As Long
   
hWnd = frm.hWnd
    
    ' Let's get first Child Window of the FORM
    hWnd_VSB = apiGetWindow(hWnd, GW_CHILD)
                
    ' Let's walk through every sibling window of the Form
    Do
        ' Thanks to Terry Kreft for explaining
        ' why the apiGetParent acll is not required.
        ' Terry is in a Class by himself! :-)
        'If apiGetParent(hWnd_VSB) <> hWnd Then Exit Do
            
        If fGetClassName(hWnd_VSB) = "scrollBar" Then
            lngStyle = apiGetWindowLong(hWnd_VSB, GWL_STYLE)
            If (lngStyle And SBS_SIZEBOX) = False Then
                'If apiGetWindowLong(hWnd_VSB, GWL_STYLE) And SBS_HORZ Then
                 If (lngStyle And 1) = SBS_HORZ Then
                    fIsScrollBarHZ = hWnd_VSB
                    Exit Function
                End If
            End If
        End If
    
    ' Let's get the NEXT SIBLING Window
    hWnd_VSB = apiGetWindow(hWnd_VSB, GW_HWNDNEXT)
    
    ' Let's Start the process from the Top again
    ' Really just an error check
    Loop While hWnd_VSB <> 0
    
    ' SORRY - NO Vertical ScrollBar control
    ' is currently visible for this Form
    fIsScrollBarHZ = -1
End Function
 
eatwork . . .

I've already stated:
TheAceMan said:
[blue] . . . but I've never heard of an API that can track listbox scroll bars![/blue]
[blue]Form scrollbars . . . Yes![/blue] Listbox scrollbars . . . [red]No![/red] Believe me . . . I've been through the search sooooooo many times . . . your gonna come up, zero . . . zippo . . . nada!
You need to [blue]reconsider the subform method![/blue] Its easily done in access alone (scroll and click or doubleclick to resort)!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Hello TheAceman1,
Thank you for your post. I have been able to find some API code that returns the track position of the horizontal scroll bar. The problem I am having with the x position is that the returned value, in my case, is 1-15 and not a pixel number. The track number when placed in the middle is 8 as it should be. I just don't know how to convert the returned value to pixels. Any ideas? Thank you.

code thanks to Stephen Lebans
Code:
Public Function GetScrollBarListBoxPosHZ(ByVal lstListbox As ListBox) As SCROLLINFO
Dim lsthWndSB As Long
Dim lngret As Long
Dim sInfo As SCROLLINFO
    
    ' Init SCROLLINFO structure
    sInfo.fMask = SIF_ALL
    sInfo.cbSize = Len(sInfo)
    sInfo.nPos = 0
    sInfo.nTrackPos = 0
    
    lstListbox.SetFocus
    lsthWndSB = GetFocus()
       
    ' Get the window's ScrollBar position
    lngret = apiGetScrollInfo(lsthWndSB, SB_HORZ, sInfo)
    GetScrollBarListBoxPosHZ = sInfo '.nMax + 1
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top