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!

Flicker free Listview

Status
Not open for further replies.

selimsl

Programmer
Aug 15, 2005
62
TR
Hi,
I am using Listview control on my project. I add items to the listview control cyclically. I mean I fill the listview with values and then after a time period I refill the listview with the new values. I do it with the code below. But everytime I refill listview it flickers. For example I drag scrollbar of listview down and when it flickers, scrollbar goes up to its default position.

The procedure below is called cyclically

Code:
        '******************************
        Dim intIndex As UInt16 = intStartingAddress
        '******************************
        'Clear Listview
        lvwDisplayData.Items.Clear()
        '******************************
        For Each intTemp As UInt16 In intArray
            'Declare a ListViewItem Object
            Dim objListViewItem As New ListViewItem
            'Set the Properties of the ListViewItem Object
            objListViewItem.Text = intIndex.ToString
            objListViewItem.SubItems.Add(intTemp.ToString)
            'Add the ListViewItem Object to the ListView
            lvwDisplayData.Items.Add(objListViewItem)
            intIndex += 1
        Next
        '******************************
 
Take a look at the following. It will cause the control to stop refreshing then once fully loaded you can turn it back on:
Code:
			lstDetail.BeginUpdate()
			'For Loop
			'    do code stuff.
			'Next
			lstDetail.EndUpdate()

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
Dear ousoonerjoe ,

I applied your suggestion on my code, but unfortunately it didn't work.

On the web I found same thread, they said DoubleBuffered solved this issue, but I don't know how to apply it on my code.
 
The problem with my code is listview.items.clear()

I have created a form that uses ListView. How do I clear the contents of the listview so that I can update the data?
If I use clear keyword this causes strange behaviour I mentioned before.



 

Well, the link you posted does have an answer:

Public Class ffListView
Inherits ListView

Public Sub New()
Me.DoubleBuffered = True
End Sub
End Class

They way you would use this is to create a new class in your project, then copy this code into the class. Next, open the <formname>.designer.vb file and in it find the line that declares the listview in question. It will look something like this:

Me.ListView1 = New System.Windows.Forms.ListView

Change it to this:

Me.ListView1 = New ffListView

That should be all you need. Post back and lets us know how it goes.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
When I use ffListView Class nothing can be read from listview. I mean I added 30 rows to the listview but nothing can be read on the listview. I checked items.count property and it says count=30.

Instead of this I changed the code which was post with the code below

Code:
        '******************************
        Dim intIndex As UInt16 = 0
        '******************************
        'lvwDisplayData.BeginUpdate()
        '******************************
        For Each intTemp As UInt16 In intArray
            'Add the ListViewItem Object to the ListView
            lvwDisplayData.Items(intIndex).SubItems(1).Text = intTemp.ToString
            intIndex += 1
        Next
        '******************************
        'lvwDisplayData.EndUpdate()
        '******************************

By doing this I gave up using clear keyword and I edit rows directly with SubItems(1).Text keyword. Now scrollbar doesn't go up automatically and I can select any row. About flicker, there is still little flicker, but not so much as before. I think it is normal, isn't ?
By the way this procedure is called approximately every 300 msec.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top