-
Jun 4th, 2015, 09:07 PM
#1
Thread Starter
New Member
[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.
-
Jun 4th, 2015, 10:41 PM
#2
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.
-
Jun 4th, 2015, 10:46 PM
#3
Thread Starter
New Member
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
-
Jun 4th, 2015, 11:47 PM
#4
Re: Dynamic Variable List, How? Ex: TaskMan
Originally Posted by John.Ful
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|