ListView

Started by Douglas McDonald, January 16, 2010, 04:08:07 PM

Previous topic - Next topic

Douglas McDonald

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
Doug McDonald
KD5NWK
www.redforksoftware.com
Is that 1's and 0's or 0's and 1's?

José Roca

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.

Paul Squires

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

Paul Squires
PlanetSquires Software

Douglas McDonald

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   



Doug McDonald
KD5NWK
www.redforksoftware.com
Is that 1's and 0's or 0's and 1's?

Douglas McDonald

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
Doug McDonald
KD5NWK
www.redforksoftware.com
Is that 1's and 0's or 0's and 1's?

Paul Squires

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.

Paul Squires
PlanetSquires Software

Paul Squires

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!
:)
Paul Squires
PlanetSquires Software

Douglas McDonald

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
Doug McDonald
KD5NWK
www.redforksoftware.com
Is that 1's and 0's or 0's and 1's?

Elias Montoya

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. :)
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.