帮助后台工作人员加载列表视图 [英] help loading a listview with a background worker

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

问题描述

我有这段代码可以读取文件,并将所有信息从文件中列出到列表视图中.当我运行它时,列表视图会加载并且很漂亮,但是当它有很多要加载的项目时,加载时看起来会显得不稳定(列表视图闪烁).

我厌倦了使用后台工作者,但我无法加载列表视图.我看到它加载了有多少堆但没有其他数据的计数.如果有人有任何建议,请.


这是我正在使用的完整代码:(整个项目都在单击按钮中)

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)

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

推荐答案



您可以尝试在更新列表之前添加SuspendLayout,然后添加ResumeLayout,但不确定是否足够.
另一种可能性是在单独的列表中构建项目列表,并在完成后将其应用于控件.

Piet
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


我所做的是对列表视图使用隐藏和显示,并使其在新线程中运行.这将在应用程序运行时隐藏列表视图,直到完成加载,然后显示.
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.


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

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