PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Douglas McDonald on January 16, 2010, 04:08:07 PM

Title: ListView
Post by: Douglas McDonald on January 16, 2010, 04:08:07 PM
How do I set the Top Index of the list view control. There is a GetTopIndex function but no SetTopIndex.

What I want to do is keep the last item in the list visible as the last line. The list is auto updating so items are always being added.

Thank you
Doug
Title: Re: ListView
Post by: José Roca on January 16, 2010, 04:26:33 PM
Send the message LVM_ENSUREVISIBLE


SendMessage(hwndLV, %LVM_ENSUREVISIBLE, i, MAK(LONG, fPartialOK, 0))


Where hwndLV is the handle of the ListView control, i the zero-based index or the item, and fPartialOK is 0 or 1.
Title: Re: ListView
Post by: Paul Squires on January 16, 2010, 04:46:07 PM
Here is a demo to try. Simple form with a listview and a timer. Ensure that your listview has the LVS_SINGLESEL windowstyle set.


'--------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
                         hWndForm As Dword, _      ' handle of Form
                         ByVal UserData As Long _  ' optional user defined Long value
                         ) As Long

   Local lv    As Dword
   
   lv = HWND_FORM1_LISTVIEW1
   
   FF_ListView_InsertColumn lv, 0, "Column 1", %LVCFMT_LEFT, 200
   FF_ListView_InsertColumn lv, 1, "Column 2", %LVCFMT_RIGHT, 85
   FF_ListView_InsertColumn lv, 2, "Column 3", %LVCFMT_LEFT,  50

End Function


'--------------------------------------------------------------------------------
Function FORM1_TIMER1_WM_TIMER ( _
                               hWndForm      As Dword, _  ' handle of Form
                               wTimerID      As Dword  _  ' the timer identifier
                               ) As Long

   Local nCount As Long 
   Local lv     As Dword
   Static p     As Long
   
   lv = HWND_FORM1_LISTVIEW1

   ' increment our sample data
   Incr p

   ' Because count is one based, inserting using this value essentially
   ' appends to the listview
   nCount = FF_ListView_GetItemCount( lv )

   FF_ListView_InsertItem lv, nCount, 0, Str$(p)
   FF_ListView_InsertItem lv, nCount, 1, Str$(p)
   FF_ListView_InsertItem lv, nCount, 2, Str$(p)

   FF_ListView_SetSelectedItem lv, nCount
   ListView_EnsureVisible lv, nCount, %FALSE

End Function

Title: Re: ListView
Post by: Douglas McDonald on January 16, 2010, 05:33:46 PM
I guess I didn't explain it correctly. instead of the data scrolling off the end (bottom) of the list I want the last data point AT the bottom of the Visible list or I suspose you could say to scroll off the top of the list


         Local lstcnt As Long
         lstcnt =FF_ListView_GetItemCount( HWND_FRMDMM_LISTVIEW1 )
         ztrace Str$(lstcnt)
         If lstcnt (24 mod 24) = 0 Then 'If at end of Visible  part of list set top index to 'lstcnt
           SendMessage(HWND_FRMDMM_LISTVIEW1, %LVM_ENSUREVISIBLE, lstcnt, Mak(Long, 1, 0))
         End If   



Title: Re: ListView
Post by: Douglas McDonald on January 17, 2010, 09:32:57 PM
I suppose another way to explain it is once a certen number of items are in the in the listview I want the topindex to be topindex -1. So as new items are added to the list the oldest 'scrolls' (appears to scroll) off the top of the list. This has the effect that the last item is always in the visible part of the list.

To put it another way:

If the visible list can contain 24 items then the 25th is added to the list the first item (index 0) scrolls off the top of the list and item index (1) is now at the top of the list.

Problem is that there is not a SET TopIndex function. Only a GET topIndex function. How do I set the TopIndex ??

Thank you

BTW, I've been using FF3 for a few days now and it was money well spend. I like it a lot.

Thank you

Doug
Title: Re: ListView
Post by: Paul Squires on January 17, 2010, 11:33:20 PM
Quote from: Douglas McDonald on January 17, 2010, 09:32:57 PM
If the visible list can contain 24 items then the 25th is added to the list the first item (index 0) scrolls off the top of the list and item index (1) is now at the top of the list.

I thought that was exactly what the code I posted above did? The new rows are constantly added to the end of the list, Listview_EnsureVisible scrolls it into view as the last line, forcing the top item to scroll off the top of the list. Did you try the code in a test project to see if that is the effect that you're looking for? I don't think that there is a winapi function specifically for setting the top index.

Title: Re: ListView
Post by: Paul Squires on January 17, 2010, 11:33:58 PM
Quote from: Douglas McDonald on January 17, 2010, 09:32:57 PM
BTW, I've been using FF3 for a few days now and it was money well spend. I like it a lot.

That is excellent to hear! Thanks!
:)
Title: Re: ListView
Post by: Douglas McDonald on January 18, 2010, 12:04:10 PM
Thanks Paul, I did try your code in my app and it had no effect at first. My mistake was using the incorrect index, it works as expected now.

Lesson learned----Try your sample code in a new project first. Sorry about that

Doug
Title: Re: ListView
Post by: Elias Montoya on January 18, 2010, 01:23:46 PM
Quote from: Douglas McDonald on January 17, 2010, 09:32:57 PM
BTW, I've been using FF3 for a few days now and it was money well spend. I like it a lot.

Ditto. Im almost finishing my first FF3 project. :)