PC Review


Reply
Thread Tools Rate Thread

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

 
 
Henry
Guest
Posts: n/a
 
      26th Feb 2004

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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      26th Feb 2004
* Henry <(E-Mail Removed)> scripsit:
> 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'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet/>
 
Reply With Quote
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      26th Feb 2004
Hi,

The listview has a topitem property.
http://msdn.microsoft.com/library/de...pitemtopic.asp

Ken
---------------------
"Henry" <(E-Mail Removed)> wrote in message
news:O0pQeFJ$(E-Mail Removed)...
>
> 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
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
Henry
Guest
Posts: n/a
 
      26th Feb 2004
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Henry
Guest
Posts: n/a
 
      26th Feb 2004
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.......

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there an API call to get the system's ListView sort arrows imagelist? jrhoads23@hotmail.com Microsoft C# .NET 1 13th Jan 2005 10:06 PM
Is there an API call to get the system's ListView sort arrows imagelist? jrhoads23@hotmail.com Microsoft Dot NET Framework Forms 1 13th Jan 2005 10:06 PM
Is there an API call to get the system's ListView sort arrows imagelist? jrhoads23@hotmail.com Microsoft VB .NET 1 13th Jan 2005 10:06 PM
Why does ListView.Sorting call RecreateHandle? Samuel R. Neff Microsoft C# .NET 0 20th Dec 2004 10:00 PM
RE: Listview tooltips not working properly Gary Chang Microsoft VC .NET 4 24th Feb 2004 02:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:09 PM.