Link to home
Start Free TrialLog in
Avatar of jackjeckyl
jackjeckyl

asked on

Automatically refresh a listview box

Is it possible to automatically refresh a listview box that is populated with database (SQL 2000) info?  The situation is this: we process work throughout the day and I want the listview box to continually show the totals as they are entered.  I don't want to bog down memory by doing a constant refresh, so is there a simpler and easier way to do this?  The individual data is ultimately going to be extracted to a file if the totals on the screen match the operator totals.  It doesn't have to be a listview box, but it should have similar functionality.  If it can be done, please leave me detail code on the refresh or what specifically should be done.  Thanks!
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or more simpler, use the example above:

Sub TimerRefresh_Timer()
   'refresh ListView control processes
End Sub

and set the Timer Interval to certain period.

Example:

TimerRefresh.Interval = 5000 '5 seconds

so that each 5 seconds will be a refresh process on ListView.

disable the timer (TimerRefresh.Enable = False) when no need to refresh the ListView.
Even though the ryancys answer is simpler, you will be limited to the 65 second maximum interval of the timer.

My example does the refresh every five minutes.

=================================================
A more efficient alternative would be to do some efficient check of the database for a change and only then do the ListView refresh.
Avatar of RainUK
RainUK

listening..
Hi jackjeckyl,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept ryancys's comment(s) as an answer.
    *** aikimark, there is no 65-second limit

jackjeckyl, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
DanRollins,

From the online VB help for the Timer Control's INTERVAL property:

The settings for milliseconds are:

Setting     Description
0     (Default) Disables a Timer control.

1 to 65,535      Sets an interval (in milliseconds) that takes effect when a Timer control's Enabled property is set to True. For example, a value of 10,000 milliseconds equals 10 seconds. The maximum, 65,535 milliseconds, is equivalent to just over 1 minute.
_______________________________________________
So what did you mean by your comment:
"*** aikimark, there is no 65-second limit"  ?

===================================================
With the questioner's requirement being "...don't want to bog down memory by doing a constant refresh...", I think my method is a better solution in that it allows the user to set a refresh rate beyond the maximum interval of the timer.  Of course, the questioner may choose to dynamically set the refresh interval during the day for known busy periods or change the refresh interval depending on the number of records that might have changed in the most recent refresh.
Sorry aikimark, you are correct. I was able to dig up this from MSDN:
Limitations of the Windows Forms Timer Component's Interval Property
The interval can be between 1 and 64,767, inclusive, which means that even the longest interval will not be much longer than one minute (about 64.8 seconds).
...and elsewhere, referring to SetTime API...
The Timer control allows a maximum interval of slightly over a minute while these API functions allow you to set an interval up to 24.86 days.

Before posting my comment, I checked the Win32 API and saw the latter value and then I did a quick sanity check on VB.NET dox and saw that the parameter is of type 'double' with no mention whatsoever of a limit (though digging deeper, I see that this 65-second limit appears to apply to VB.NET, C# and Windows.Forms in general).   I just now did a test with window.setInterval in HTML Jscript and VBSCRIPT there is no 65-second limit.

I am still incredulous that a ridiculous 16-bit constraint is placed on the Timer control which has had plenty of time to be brought up to 32-bit standards.

Since you mentioned timers first, I am changing my recommendation to:

   Accept aikimark's comment(s) as an answer.
==========
DanRollins -- EE database cleanup volunteer
Avatar of jackjeckyl

ASKER

I am not interested in using timers to alleviate this problem.  I was hoping to have a more "real time" listview.  I would like this question deleted and my points credited back.
lol.  Seven months later, jackjeckyl comes along and revises the parameters of what would be an acceptable answer.   A timer is the only answer.  Well, except perhaps magic or ESP.
jackjeckyl asked to get this question deleted. If ther are no objections I will

    PAQ and refund

in 72 hours.

** Mindphaser - Community Support Moderator **
I object.

jackjeckyl sat on this question for over half a year.  Now that we're about to disburse his points, he raises an objection.  This is suspicious timing.

There are other ways to trigger events and any of them can cause the refresh of your listview.  Using a timer ensures your application that a refresh will happen no longer than a certain interval.  Thus, we experts think that a timer is a good choice.  We never got to the details of the update process.  Nor did we discuss any of the alternatives while you were briefly involved with this question.

I'll be glad to continue this discussion if you want some value for your 200 points.
Whats suspicious?  Timers are not what I'm looking for.  Besides, I didn't put a 200 point question out here for a simplistic "use a timer" answer.  I wanted something advanced, something like an agent watching when data is entered into a table and firing off a job to notify VB or another executable or somethin!  If these guys want points, split 50 between them, but no way do they deserve 200.  They didn't answer anything, just made a suggestion I'm not going to use.  
jackjeckyl,

What is suspicious is your timing.  Back when you opened your question, you gave us very few restrictions and requirements upon which to base our recommendations.  You disappeared from this discussion and gave us no hint that you were not satisfied with the direction and specifics of our comments.  Only when you thought you were going to lose 200 points did you raise an objection.  THAT timing is suspicious.

Since you entered this question in the VB area, we started with VB solutions.  It has been a week since your last comment on this thread.  Shall we (experts) assume that is an average response time for you on this question?  Since this question is rather old, you might want to post another question and refer to this question.  Post new (referal) questions in both the VB and the SQL Server areas.
_________________________________________
There are two basic solutions to this problem:
1. The client program asks the database if there are changes.
2. The database broadcasts change announcements to the clients.

For the first scenario, you may query the database as the user's actions cause events or your program causes events (ala Timer recomendations).  By far this is the simpler solution.

The second scenario is more complicated.  You will need to create triggers for the table(s) in question, thus degrading the overall performance of that database table.  You will need to establish some communication mechanism between the database and the program.  You will also need to be aware of security restrictions (firewalls) and have a robust broadcast mechanism that tolerates communcations outages.  You will also need to have the network capacity to accomodate a lot of broadcast messages.  

You may also need some minimun interval between listview refreshes, since EVERY client will do a refresh subsequent to EVERY table update/insert/delete!

Remember that if the program initiates code that 'looks' for a change indicator that was placed in some location, then you are back in the first scenario.
__________________________________________
What kind of requirements do you want to place on our solution?

Sometimes people offer higher points because they have an urgent problem.  Your question does not appear to fit into the pressing-need category.
aikimark, the second part is exactly what I am looking for.  But as my original question requested, leave some detailed code on how this could be done.  I don't have the capabilities to just churn something like that out, so I was looking for what I hoped to be an easier solution.  I agree that I should have said "no, I don't want timers" months ago.  I'm fine with you getting or splitting 50 points, because lets face it you didn't give me a 200 point answer.  
Answered by aikimark.  
I cannot penalize the experts because A) you didn't specify your requirements up front, B) you didn't provide the experts with feedback as to whether or not you are satisfied with any of the answers, C) They do not know your skill level.  

This is not the first time you have requested a refund on a "Stale" answer as you call it when you were not the last person to comment in your question.  It is important that you provide feedback to the experts who are donating their time to assist you with your questions.  My advice is to always be the last person to comment on your questions.

The experts here have no idea of what your skill level is or whether or not you are familiar with the Timer control.  It is the questioner's responsibility to assign the point value.  I've seen 500 point Qs answered with a simple "you need to dimension your variable" and I've seen 20 point questions which required 500 lines of code and 12 days of explanation to the questioner.

Fully stating your requirements up-front and participating in the questions you have asked will help greatly in the future.  There are some great tips in this area to avoid thee sort of problems in the future: https://www.experts-exchange.com/Community_Support/New_to_EE/

All that said, I would hope that the experts continue to assist you with this question until you are fully satisfied, but they are under no obligation to do so.

SpideyMod
Community Support Moderator @Experts Exchange