Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code that reads a file and list all the information from it to a listview. When i run it the list view loads and its nice but when it has a lot of items to load its gets choppy looking(listview flashing) when its loading.

i tired using a background worker but i cant get it to load the listview. I see it load the count of how many heaps are there but no other data. If anyone has any sugestions please.


here is the full code i m using:(this whole item is in a button click)

VB
objsh = CreateObject("WScript.Shell")
        Dim strObject As String = "C:\Temp\ASERVICE.EDM"
        Dim process = GetObject("winmgmts://./root/novadigm:NVD_Agent")
        Dim method = process.Methods_("GetValue")
        Dim inParameters = method.inParameters.SpawnInstance_()
        inParameters.Path = strObject
        Dim outParameters = process.ExecMethod_("NumberOfInstances", inParameters)
        Dim StrHeaps = (outParameters.InstanceCount)
        Cae1.CAE_Heap_Count.Text = StrHeaps
        For i = 0 To StrHeaps Step 1

            inParameters.Index = i

            inParameters.Property = "ZOBJNAME"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim Value2 As String = outParameters.Value

            inParameters.Property = "ZAVIS"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim Value3 As String = outParameters.Value

            inParameters.Property = "ZSVCCSTA"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim Value4 As String = outParameters.Value

            inParameters.Property = "NAME"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim Value5 As String = outParameters.Value

            inParameters.Property = "INSTDATE"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim value6 As String = outParameters.Value

            inParameters.Property = "ZVERIFY"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim value8 As String = outParameters.Value

            'Date
            Dim str As String
            Dim strArr() As String
            Dim count As Integer
            Dim value7 As String
            str = value6
            strArr = str.Split("T")
            For count = 0 To strArr.Length - 2
                value7 = (strArr(count))
            Next

            Dim value1 = Cae1.CAE_Listview.Items.Count
            Dim item As New ListViewItem(value1)
            item.SubItems.Add(Value2)
            item.SubItems.Add(Value3)
            item.SubItems.Add(Value4)
            If Value4 = "999" Then
                item.BackColor = Color.Gold
            End If
            If Value4 = "324" Then
                item.BackColor = Color.Gold
            End If
            If Value4 = "209" Then
                item.BackColor = Color.Red
            End If
            If Value4 = "709" Then
                item.BackColor = Color.Red
            End If
            If Value4 = "810" Then
                item.BackColor = Color.Red
            End If
            If Value4 = "811" Then
                item.BackColor = Color.Red
            End If
            item.SubItems.Add(Value5)
            item.SubItems.Add(value7)
            item.SubItems.Add(value8)
            Cae1.CAE_Listview.Items.Add(item)
            Cae1.CAE_Listview.FullRowSelect = True

        Next
        Cae1.CAE_Listview.Items(Cae1.CAE_Listview.Items.Count - 1).Remove()
Posted

Hi,

You could try to add SuspendLayout before and ResumeLayout after update the list, but not sure this is enough.
Another possibility is to build the list of Items in an separate list and apply them to the control when you're done.

Piet
 
Share this answer
 
Comments
Zachary.shupp 2-Mar-12 16:11pm    
could you give me an example of how to suspendlayout and resumelayout?
Zachary.shupp 2-Mar-12 16:19pm    
I tried using suspendlayout at the begining nad resumelayout at the end of the code and it still loaded the sameway.
What I did was use hide and show for the listview and have it run in a new thread. This wAy when the the application runs it will hide the listview till its finished loading and then it will show.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900