How to update listview ONLY when new data is avilable?

You can talk about VB programming here

How to update listview ONLY when new data is avilable?

Postby method » Fri May 04, 2007 9:11 pm


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 dynamic xml 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
Last edited by method on Fri May 04, 2007 9:34 pm, edited 1 time in total.
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby Ghost » Fri May 04, 2007 9:20 pm

[vb]If rss <> listview then
refresh
End If[/vb]

Tried that?
Ghost
 

Postby method » Fri May 04, 2007 9:32 pm

ghoast . Could you explain to me how to use that and how it works? I never seen it before :-(( . Acutally the dynamic data is not rss. It is just dynamic xml generated from remote mysql)
Last edited by method on Fri May 04, 2007 9:36 pm, edited 1 time in total.
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby Departure » Fri May 04, 2007 10:14 pm

ghost wrote if rss is diffrent from listview then call the refresh function
User avatar
Departure
Global Moderator
Global Moderator
 
Posts: 996
Joined: Thu Mar 17, 2005 11:26 am
Location: Australia

Postby Ghost » Fri May 04, 2007 11:04 pm

Yep, exactly what Dep said...

All it's doing is comparing the XML with the listview and seeing if they're the same. If they're not, then, like Dep said, it calls the function to refresh. I just put "refresh" in there because I figured it'd be easier to understand :P

Hope you understand it now...
Ghost
 

Postby method » Fri May 04, 2007 11:21 pm

Thanks for both of you. ok. So how to compare rss with current listview? i posted my simple xml that is generated by php

Code: Select all
<playlist>
  <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>
Last edited by method on Fri May 04, 2007 11:25 pm, edited 3 times in total.
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby Ghost » Sat May 05, 2007 2:14 am

What's outputting to the listview? The whole XML file? Like, the artist, name, image, etc.? Or is it just the name of the song?
Ghost
 

Postby method » Sat May 05, 2007 6:56 am

The whole xml file.
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby autopilot » Sat May 05, 2007 7:17 am

what I would do, is more like this[vb]If rss <> rsscopy Then
rsscopy = rss
refreshlistview
End If[/vb]
User avatar
autopilot
Forum Moderator
Forum Moderator
 
Posts: 358
Joined: Sat Sep 23, 2006 7:19 pm

Postby Ghost » Sat May 05, 2007 10:06 am

autopilot wrote:what I would do, is more like this[vb]If rss <> rsscopy Then
rsscopy = rss
refreshlistview
End If[/vb]


That's exactly what I was going to tell him to do next. Make a second, hidden listview and check it against the one displayed.
Ghost
 

Postby method » Sun May 06, 2007 8:13 am

Ghost wrote:
autopilot wrote:what I would do, is more like this[vb]If rss <> rsscopy Then
rsscopy = rss
refreshlistview
End If[/vb]


That's exactly what I was going to tell him to do next. Make a second, hidden listview and check it against the one displayed.


Thanks for your suggestion .So if i need make to make a new listview do you think this line :If rss <> rsscopy
will do the compar? rss and rsscopy are listview names? If not . could any one show me how to compare them?
Last edited by method on Sun May 06, 2007 1:06 pm, edited 1 time in total.
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby Ghost » Sun May 06, 2007 7:47 pm

No, rss and rsscopy are what you've named the listviews. If you've named them rss and rsscopy, then yes, that'll work. Otherwise, it's whatever you've named them. Does that make sense?
Ghost
 

Postby autopilot » Sun May 06, 2007 9:08 pm

rss & rsscopy are the names of xml files... rss is the source xml and rsscopy would be a copy of rss... if those are the names of the xml files, then the if statement should work to compair the 2 xml files.

autopilot
User avatar
autopilot
Forum Moderator
Forum Moderator
 
Posts: 358
Joined: Sat Sep 23, 2006 7:19 pm

Postby Ghost » Sun May 06, 2007 10:00 pm

Oh, you're doing it that way. I was thinking of loading the xml files into the program first... Autopiolt's way would probably use less CPU, thus making it better. :P
Ghost
 

Postby method » Mon May 07, 2007 7:54 pm

Ghost wrote:Oh, you're doing it that way. I was thinking of loading the xml files into the program first... Autopiolt's way would probably use less CPU, thus making it better. :P


This is how i populate my listview. How to compare it with old listview data?I am totaly lost with your replies:-(


Dim objDoc As MSXML2.DOMDocument
Dim objNodelist As IXMLDOMNodeList
Dim objNode As IXMLDOMNode
Dim lvwItem As ListItem


'load the xml document
Set objDoc = New MSXML2.DOMDocument
objDoc.async = False
objDoc.Load "http://localhost/xmloutput.php"

'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
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Next

Return to Visual Basic Programming

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests