Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get some help with a background worker. I have this code below that will read a file and list its information, this file can have any where from 35 to 400 items listed and when i run it the listview flashes till its done loading and i want it to load all at one time or at leats load without the flashing. Any help would be great and if you have an answer can you please provide an example i haven't ever worked with list views or data grids.

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

I don't see where the BackgroundWorker comes into this. Hopefully, you're not trying to update the ListView control at all from inside the BackgroundWorker code, but...

To stop the control from updating, just call CAE_ListView.BeginUpdate. When you're done adding items to it, EndUpdate. During this time, the control will appear unresponsive, so don't take forever to update the list.
 
Share this answer
 
Comments
Zachary.shupp 5-Mar-12 21:57pm    
I have tried having using the whole code in a background worker and it didn't work and then I used background worker do work with just the values and got it to show the first entry and that was it. At what point would I use begin update.?
Would it be right before cae_listview.items.add(item ) and then place the end update after.

I would like to have the whole list view load all at the same time. Would this method do that or do I need to go another route to have it load all at once?
what i have done is before the listview loads i hide it and when its finished i show the listview which helps out.
 
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