Results 1 to 3 of 3

Thread: ListView update

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    ListView update

    My listview clears and updates every 2seconds. Is there an easy to refresh the list information with out clearing first?

    Like taskmanager

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: ListView update

    You loop through the items and edit them as needed. Each item has a Text property and a SubItems property. Each subitem also has a Text property. Just make sure that you call BeginUpdate first and EndUpdate at the end, to make sure that the ListView only repaints once rather than after each change.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Re: ListView update

    Evening john. I'm a little stuck. I tried

    Code:
    If lvDisplayRunningProcesses.FindItemWithText(Process.ProcessName) Is Nothing Then
    which in theory worked. But would stop duplicates of items such as svchost.exe etc

    Here is my full code. (I did read what you posted, and it makes poerfect sense, just i'm a little confused.)

    Code:
        Private Sub DisplayCurrentlyRunningProcesses()
    
            ' lvDisplayRunningProcesses.Items.Clear()
    
            Dim RunningProcesses() As Process = Process.GetProcesses()
    
            Try
                For Each Process In RunningProcesses
                    Dim ProcessID As Process = System.Diagnostics.Process.GetProcessById(Process.Id())
                    Dim lstThreads As ProcessThreadCollection = ProcessID.Threads
                    Dim lvi As ListViewItem = New ListViewItem()
                    Dim arryThreads As New List(Of Integer)
                    Dim Location As String = ProcessID.MainModule.FileName.ToString
    
    
                    cpuCounter = New PerformanceCounter()
                    cpuCounter.CategoryName = "Process"
                    cpuCounter.CounterName = "% Processor Time"
                    cpuCounter.InstanceName = Process.ProcessName
    
                    ' Count all attached threads 
                    For x As Integer = 0 To lstThreads.Count - 1
                        arryThreads.AddRange(New Integer() {x})
                    Next
    
                    If lvDisplayRunningProcesses.FindItemWithText(Process.ProcessName) Is Nothing Then
                        lvi.Text = Process.ProcessName & ".exe"
                        lvi.SubItems.Add(Process.Id.ToString())
                        lvi.SubItems.Add(cpuCounter.NextValue() & "%")
                        lvi.SubItems.Add(arryThreads.Count.ToString)
                        lvi.SubItems.Add(Process.WorkingSet64 / 1024 & " K")
                        lvi.SubItems.Add(Process.PriorityClass.ToString)
    
    
                        Try
                            lvi.SubItems.Add(Process.MainModule.FileVersionInfo.CompanyName)
                        Catch ex As ArgumentException
    
                        End Try
    
                        lvi.SubItems.Add(Location)
                        lvDisplayRunningProcesses.Items.Add(lvi)
                    End If
                Next
    
            Catch ex As Win32Exception
    
            Catch ex As ArgumentOutOfRangeException
    
            End Try
    
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width