用后台工作人员加载一个listview [英] loading a listview with a background worker

查看:63
本文介绍了用后台工作人员加载一个listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力寻求有关后台工作者的帮助.我在下面的这段代码中将读取一个文件并列出其信息,该文件可以列出35到400个项目中的任何一个,当我运行它时,listview会一直闪烁,直到完成加载为止,并且我希望一次全部加载它,或者在负载不闪烁的情况下.任何帮助都将是非常有用的,如果您有答案,请提供一个我从未使用过列表视图或数据网格的示例.

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.

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()

推荐答案

我看不到BackgroundWorker出现在哪里.希望您根本不打算从BackgroundWorker代码内部更新ListView控件,但是...

要停止更新控件,只需调用CAE_ListView.BeginUpdate.完成向其中添加项目后,请选择EndUpdate.在这段时间里,控件将显示为无响应,因此不要花费太多时间来更新列表.
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.


我所做的是在列表视图加载之前,我将其隐藏以及完成后,显示有助于解决问题的列表视图.
what i have done is before the listview loads i hide it and when its finished i show the listview which helps out.


这篇关于用后台工作人员加载一个listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆