eikal 0 Light Poster

hi i was reading my book and it was teaching me about LINQ and it had me create a form that displayed the all the system processes in a datagridview control. the code they gave me was this

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'displays the current system processes.
        Dim myquery = From anitem In Process.GetProcesses _
                Select anitem.ProcessName, anitem.Threads.Count, anitem.Responding
        DataGridView1.DataSource = myquery.ToList
    End Sub

now that was the end of the example... after creating this i wanted to make a button that could kill a selected process. in order to do that first i will have to initiate myquery at the module level. So... I THOUGHT that putting the code like this would work...

private myquery = From anitem In Process.GetProcesses _
                Select anitem.ProcessName, anitem.Threads.Count, anitem.Responding
        DataGridView1.DataSource = myquery.ToList

and leaving the datagridview1.datasource = myquery.tolist in form load. but when i do that the form crashes and does not start up. So firstly i would like to know how to declare it at a module level. THEN after that... i would want to know how to kill the currently selected process.. im thinking it would look something like this

if datagridview1.selectedcells = anitem.processname then
anitem.kill
end if

i know this code isn't accurate but that is my best attempt at figuring out how to do it. :/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.