Solved

Automatically refresh a listview box

Posted on 2002-07-10
15
1,157 Views
Last Modified: 2008-02-01
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!
0
Comment
Question by:jackjeckyl
  • 5
  • 3
  • 3
  • +4
15 Comments
 
LVL 45

Accepted Solution

by:
aikimark earned 200 total points
ID: 7144926
The simplest manual refresh can be written in a Timer control's Timer event.

Sub TimerRefresh_Timer()
    Static dtNextRefresh As Date
    If dtNextRefresh = 0 Then
        dtNextRefresh = DateAdd("n", 5, Now)
    End If
    If dtNextRefresh < Now Then
        'refresh ListView control

        dtNextRefresh = DateAdd("n", 5, Now)
    End If

End Sub
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7145399
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.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 7145944
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.
0
 
LVL 5

Expert Comment

by:RainUK
ID: 7152124
listening..
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8002285
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
0
 
LVL 45

Expert Comment

by:aikimark
ID: 8003351
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.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8004254
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
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:jackjeckyl
ID: 8011562
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.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8011959
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.
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 8012838
jackjeckyl asked to get this question deleted. If ther are no objections I will

    PAQ and refund

in 72 hours.

** Mindphaser - Community Support Moderator **
0
 
LVL 45

Expert Comment

by:aikimark
ID: 8013397
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.
0
 

Author Comment

by:jackjeckyl
ID: 8059659
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.  
0
 
LVL 45

Expert Comment

by:aikimark
ID: 8059876
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.
0
 

Author Comment

by:jackjeckyl
ID: 8060569
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.  
0
 

Expert Comment

by:SpideyMod
ID: 8095238
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: http://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
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now