API call to GetTopIndex not working for Listview (vb.net)

H

Henry

I'm trying to get the index of the top row in the display area of a
listview (vb.net) by doing an api call to ListView_GetTopIndex. See code
below. The call is returning a 0. The SDK doc states that
ListView_GetTopIndex "Retrieves the index of the topmost visible item
when in list or report view." The listview that I'm using is in details
view. There is no "report view" in VB.Net for listview. It apears to me
that ListView_GetTopIndex will not work with a listview in details view.

Any ideas/alternatives/help appreciated.

Dim lstvScriptsFirstVisibleRow As Int32
lstvScriptsFirstVisibleRow =
Me.ListView_GetFirstVisibleRow(lstvScripts.Handle)

Private Const LVM_FIRST = &H1000
Private Const LVM_GETCOUNTPERPAGE As Long = (LVM_FIRST + 40)
Private Const LVM_GETTOPINDEX = (LVM_FIRST + 39)
Private Declare Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Int32, ByVal wParam
As Int32, ByVal lParam As Int32) As Long

Private Function ListView_GetFirstVisibleRow(ByVal hwndlv As IntPtr) As
Long
ListView_GetFirstVisibleRow = SendMessage(hwndlv,
LVM_GETTOPINDEX, 0, 0)
End Function
 
H

Herfried K. Wagner [MVP]

* Henry said:
I'm trying to get the index of the top row in the display area of a
listview (vb.net) by doing an api call to ListView_GetTopIndex. See code
below. The call is returning a 0. The SDK doc states that
ListView_GetTopIndex "Retrieves the index of the topmost visible item
when in list or report view." The listview that I'm using is in details
view. There is no "report view" in VB.Net for listview. It apears to me
that ListView_GetTopIndex will not work with a listview in details view.

Any ideas/alternatives/help appreciated.

Dim lstvScriptsFirstVisibleRow As Int32
lstvScriptsFirstVisibleRow =
Me.ListView_GetFirstVisibleRow(lstvScripts.Handle)

Private Const LVM_FIRST = &H1000
Private Const LVM_GETCOUNTPERPAGE As Long = (LVM_FIRST + 40)
Private Const LVM_GETTOPINDEX = (LVM_FIRST + 39)
Private Declare Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Int32, ByVal wParam
As Int32, ByVal lParam As Int32) As Long

Replace all 'As Long' with 'As Int32'.
 
H

Henry

Per suggestion I replaced all "longs' with int32 and I still get the
same result i.e. "0".

Changed code is below:

Dim lstvScriptsFirstVisibleRow As Int32
lstvScriptsFirstVisibleRow =
Me.ListView_GetFirstVisibleRow(lstvScripts.Handle)

Private Const LVM_FIRST = &H1000
Private Const LVM_GETCOUNTPERPAGE As Int32 = (LVM_FIRST + 40)
Private Const LVM_GETTOPINDEX = (LVM_FIRST + 39)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal
lParam As Int32) As Int32


Private Function ListView_GetFirstVisibleRow(ByVal hwndlv As IntPtr) As
Int32
ListView_GetFirstVisibleRow = SendMessage(hwndlv, LVM_GETTOPINDEX, 0,
0)
End Function
 
H

Henry

The reason I did not use TopItem was that it was too easy.

Actually, sometimes you don't see the obvious, especially when its
staring at you right in the face. However, there are so many properties,
etc. that exist sometimes you skip right over them. That's exactly what
I did.

Topitem worked. Tks much.......
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top