• Welcome to PlanetSquires Forums.
 

Keeping a list counter updated

Started by John Montenigro, December 16, 2009, 09:07:44 AM

Previous topic - Next topic

John Montenigro

In message #54 of: http://www.planetsquires.com/protect/forum/index.php?topic=2133.45, I read this reply from Rolf:
QuoteAs for the Add record function be aware that I do no update the grid after an Add. You must refresh the recordset by either doubleclicking on the table in the treeview or by a click on the QuickSQL button. This loads the records new.
and it got me wondering if the refresh could be done automatically.

I faced something similar (but simpler), so I thought I'd share what I had done, in case it might be helpful. 

I have a listbox that contains many lines of dates, and I show the user:
- How many lines of dates are in the listbox.
- How many lines of dates are selected.

Macro mUpdateListCounts
   FF_Control_SetText (HWND_FRMMAIN_LBLDATESINLIST, Str$(Listbox_GetCount(HWND_FRMMAIN_LSTDATES)))           
   FF_Control_SetText (HWND_FRMMAIN_LBLDATESSELECTED, Str$(Listbox_GetSelCount(HWND_FRMMAIN_LSTDATES)))       
End Macro


I have command buttons that can unselect the first selection, invert all selections, unselect all, and select all.

Initially, I only used the SEL CHANGE notification for manitaining the counters. But I noticed that, when a button function was performed, the counters might not be updated, or take a long time.

So I decided to use 3 different methods for keeping the display up to date:

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Three different ways to keep the counters updated...
Function FRMMAIN_LSTDATES_LBN_SELCHANGE ( _
                                        ControlIndex  As Long,  _  ' index in Control Array
                                        hWndForm      As Dword, _  ' handle of Form
                                        hWndControl   As Dword, _  ' handle of Control
                                        idListBox     As Dword  _  ' identifier of listbox
                                        ) As Long
   'when the list selection changes:                                       
   mUpdateListCounts
End Function
Function FRMMAIN_tmrListUpdate_WM_TIMER ( _
                                 hWndForm      As Dword, _  ' handle of Form
                                 wTimerID      As Dword  _  ' the timer identifier
                                 ) As Long
   'whenever the timer fires:
   'The timer was set up by adding the Timer control to the form, and setting the interval (seconds) in Properties.
   mUpdateListCounts
End Function
Function FRMMAIN_CUSTOM ( _
                        hWndForm      As Dword, _  ' handle of Form
                        wMsg          As Long,  _  ' type of message
                        wParam        As Dword, _  ' first message parameter
                        lParam        As Long   _  ' second message parameter
                        ) As Long
   'whenever the mouse moves? (That could be a lot! anything less intense related to mouse movement?)   
   'maybe maintain a static, and only update when it hits some MOD ...???                     
   If wMsg = %WM_MOUSEMOVE Then
      mUpdateListCounts
   End If
End Function
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Eventualy I realized that I should just add my macro call to the end of each command button function... so I made those changes and all is well.

But meanwhile, I figured you never know when something might be of help to someone else, so that's why I'm sharing this. 

One thing I didn't like with detecting mouse movement was that I'm sure it was generating tons of calls that were mostly redundant - a waste of resources.

Similarly, the timer was probably overkill.

I'd appreciate hearing any other thoughts about the advantages/disadvantages of my initial approaches...