Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update listview ONLY when new data is avilable?

Status
Not open for further replies.

Edward07

Programmer
Apr 13, 2007
49
NL
Hi all. I have seen many applications that listview ONLY updates when new data is avilable or when current data changes. I am making an application that deals with similer case. But i don't know how these applications achive this task. I tried to use timer to refresh my listview every few seconds(I am loading data from rss feed to listview.)But there is a big problem that i keep losing focouse on the form and i see many unessary refreshes!! Could any one show me a better solution to avoid these unessry refreshes?I know these profitional applications are using a method that i am not aware of.Thanks

 
Part of the problem is that RSS "feeds" are anything but. There should be a law about naming things so inappropriately.

You have little choice but to poll from your application.

About all I can think of is to continue polling, possibly with a longer interval. Keep a "before image" and compare them, only updating the GUI when there is an actual change?

Depending on how you are retrieving the information and how reliable the server is about updating the timestamp (Date) header you could do an HTTP HEAD request to just get the timetamp.

There is also the If-Modified-Since request header but I'm not sure how widely it is supported on "HTTP 1.1 compliant" servers, many of which aren't.
 
Many thanks for your explantion. Actually the xml that i deal with look as follows.The xml is generated from dynamic mysql data that changes.Could you show me how i can compare xml with data in listview and if they are diffrent then i update listview whith new data.Is this the method you suggested?

Code:
  <song> 
  <artist>artistname1</artist>  
  <name>artistname1</name>  
  <image>image1.gif</image>  
  <rating>2028574083</rating>  
  <songid>566</songid>  
  <totalvotes>09898</totalvotes>  
  </song> 
      
  <song> 
  <artist>artistname2</artist>  
  <name>artistname2</name>  
  <image>image2.gif</image>  
  <rating>2028574083</rating>  
  <songid>566</songid>  
  <totalvotes>09898</totalvotes>  
  </song> 
... 
  </playlist>

vb6 code that i populate listview every 10 seconds using timer:
Code:
Private Sub PopulateListview()
Dim objDoc As MSXML2.DOMDocument
Dim objNodelist As IXMLDOMNodeList
Dim objNode As IXMLDOMNode
Dim lvwItem As ListItem


    Set objDoc = New MSXML2.DOMDocument
    objDoc.async = False
    objDoc.Load "[URL unfurl="true"]http://localhost/xml.php"[/URL]
    
    'add all the song nodes into a  nodelist
    Set objNodelist = objDoc.selectNodes("//song")
    
    'Clear the listview
    ListView1.ListItems.Clear

    'Loop through each song node and add to the list view
    For Each objNode In objNodelist
        Set lvwItem = ListView1.ListItems.Add(, , objNode.selectSingleNode("artist").Text)
        lvwItem.SubItems(1) = objNode.selectSingleNode("name").Text
        lvwItem.SubItems(2) = objNode.selectSingleNode("image").Text
        lvwItem.SubItems(3) = objNode.selectSingleNode("rating").Text
        lvwItem.SubItems(4) = objNode.selectSingleNode("songid").Text
        lvwItem.SubItems(5) = objNode.selectSingleNode("totalvotes").Text
    Next objNode
    
    Set lvwItem = Nothing
    Set objNodelist = Nothing
    Set objDoc = Nothing
End Sub
 
I'll ask the same question that I asked in your other post on this subject: why can't you simply update it whether the contents are the same or not?

Furthermore, please read faq222-2244 for how to get the best answers to your posts, in particular the explanation of the difficulties created by posting multiple times on the same subject.

Bob
 
Bob thanks for your reply.But my problem is making such compare of content. I tried like 4 method all of them failed. could you show me how to make such compar and where in my code i should do the compare?Thanks
 
All right. Sorry, got a bit confused with all the threads you have on this subject, and didn't see in this one your explanation. It seems to me that your problem isn't that you want your data to only refresh when there are changes, but that you don't want to see a regularly occurring screen refresh that doesn't do anything. So, your issue is more about the appearance of your application rather than the behavior. Is that correct?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top