Results 1 to 4 of 4

Thread: [RESOLVED] Dynamic Variable List, How? Ex: TaskMan

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2015
    Posts
    6

    Resolved [RESOLVED] Dynamic Variable List, How? Ex: TaskMan

    Q: How to add variables from a dynamic array to a Datadrigview and have them update seamlessly within the Datagridview similar to TaskManager.

    A DataTable does the job.

    Code:
    Public Class Form1
        Dim dt As New DataTable
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Timer1.Enabled = False
            Dim RunningProcesses As System.Diagnostics.Process()
            RunningProcesses = System.Diagnostics.Process.GetProcesses()
            Dim Proc As System.Diagnostics.Process
            For Each Proc In RunningProcesses
                Dim selRows As DataRow() = dt.Select("Processname='" & Proc.ProcessName & ".exe'")
                If selRows.Length > 0 Then
                    selRows(0).Item("Processname") = Proc.ProcessName & ".exe"
                    selRows(0).Item("SessionID") = Proc.SessionId
                    selRows(0).Item("ProcessID") = Proc.Id
                    selRows(0).Item("WorkingSet64") = Proc.WorkingSet64
                    selRows(0).Item("PrivateMemorySize64") = Proc.PrivateMemorySize64
                Else
                    Dim dr As DataRow = dt.NewRow
                    dr.Item("Processname") = Proc.ProcessName & ".exe"
                    dr.Item("SessionID") = Proc.SessionId
                    dr.Item("ProcessID") = Proc.Id
                    dr.Item("WorkingSet64") = Proc.WorkingSet64
                    dr.Item("PrivateMemorySize64") = Proc.PrivateMemorySize64
                    dt.Rows.Add(dr)
                End If
            Next
            iteration = iteration + 1
            ToolStripLabel2.Text = iteration
            Timer1.Enabled = True
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            dt.Columns.Add("Processname")
            dt.Columns.Add("SessionId")
            dt.Columns.Add("ProcessID")
            dt.Columns.Add("WorkingSet64")
            dt.Columns.Add("PrivateMemorySize64")
            DataGridView1.DataSource = dt
        End Sub
    End Class
    Last edited by John.Ful; Jun 4th, 2015 at 11:55 PM.

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: Dynamic Variable List, How? Ex: TaskMan

    If your not going to give a full explanation of the problem, your not going to get much help. What happens when you run the code, what's not happening, is there any errors, if so, what line. And anything other relevant information.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2015
    Posts
    6

    Re: Dynamic Variable List, How? Ex: TaskMan

    I edited the question to post the solution.

    I wanted to create a class and a list of the classes and bind them to a datagridview.
    datatable seems to do the job though

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Dynamic Variable List, How? Ex: TaskMan

    Quote Originally Posted by John.Ful View Post
    I edited the question to post the solution.
    Yeah, we'd prefer if people didn't do that... now we have a solution, but no question... so if someone is searching the forums for a similar problem, this thread may or may not show in the results, and even if it does, since they don't know what the original problem was, they may not realize the answer is here.

    Just something to remember for the future. Welcome aboard!

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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