I'm developing aplication in MS Access 2003 where I have a form with one listbox holding more items than can be shown at once. Whenever user click on some item I want to calculate (in mousedown and mouseup event) listindex of that item.
Only way I figure I could do it is dividing Y coordinate by height of one row. That way I can get index of my item relative to the top of listbox window. Problem is when list box is scrolled down and topitem visible is not actualy item with 0 listindex.
I found bunch of VB solutions for this problem using API function SendMessage with LB_GETTOPINDEX as parameter but it just doesn't seem to work with VBA
The Code I'm trying to use goes something like this:
Now, it sems that SendMessage with GETTOPINDEX or with GETITEMHEIGHT doesn't work for Access listbox. Am I right?
In both cases SendMessage returns me 0 as a result.
Itemheight I can calculate approximately and put it as constant and it will work (as long as I don't change fontsize and resolution), but I'm afraid I can't calculate item's listindex without knowing listindex of the first visible item.
Is there a way to make this code, or some other code, to work for me in this particular problem?
thanks in advance
Only way I figure I could do it is dividing Y coordinate by height of one row. That way I can get index of my item relative to the top of listbox window. Problem is when list box is scrolled down and topitem visible is not actualy item with 0 listindex.
I found bunch of VB solutions for this problem using API function SendMessage with LB_GETTOPINDEX as parameter but it just doesn't seem to work with VBA
The Code I'm trying to use goes something like this:
Code:
Private Declare Function SendMessage Lib "user32"
Alias "SendMessageA" (ByVal hwnd As Long,ByVal wMsg As Long, ByVal wParam As Integer,
ByVal lParam As Any) As Long
Private Declare Function GetFocus Lib "user32" () As Long
Const LB_GETTOPINDEX = &H18E
Const LB_GETITEMHEIGHT = &H1A1
Private Function MyListIndex(Y As Single) As Integer
DIM intTopItemIndex As Integer
DIM dblItemHeight As Double
intTopItemIndex = SendMessage(GetFocus(), LB_GETTOPINDEX, 0&, 0&)
dblItemHeight = SendMessage(GetFocus(), LB_GETITEMHEIGHT, 0&, 0&)
MyListIndex = intTopItemIndex + Y \ dblItemHeight
End Function
Now, it sems that SendMessage with GETTOPINDEX or with GETITEMHEIGHT doesn't work for Access listbox. Am I right?
In both cases SendMessage returns me 0 as a result.
Itemheight I can calculate approximately and put it as constant and it will work (as long as I don't change fontsize and resolution), but I'm afraid I can't calculate item's listindex without knowing listindex of the first visible item.
Is there a way to make this code, or some other code, to work for me in this particular problem?
thanks in advance