title: Powershell: Selecting DataGridView Row
body: <p>So far I have this code.</p>
  
  <pre class="lang-powershell prettyprint-override"><code>$form = New-Object System.Windows.Forms.Form
  $form.Size = New-Object System.Drawing.Size(900,600)
  $dataGridView = New-Object System.Windows.Forms.DataGridView
  $dataGridView.Size=New-Object System.Drawing.Size(800,400)
  $go = New-Object System.Windows.Forms.Button
  $go.Location = New-Object System.Drawing.Size(300,450)
  $go.Size = New-Object System.Drawing.Size(75,23)
  $go.text = "Select"
  $form.Controls.Add($go)
  $form.Controls.Add($dataGridView)
  
  
  $dataGridView.ColumnCount = 4
  $dataGridView.ColumnHeadersVisible = $true
  $dataGridView.Columns[0].Name = "Name"
  $dataGridView.Columns[1].Name = "ID"
  $dataGridView.Columns[2].Name = "Description"
  $dataGridView.Columns[3].Name = "Memory"
  
  $dataGridView.Columns[0].width = 240
  
  get-process | foreach {
      $dataGridView.Rows.Add($_.Name,$_.ID,$_.Description,$_.WorkingSet) | out-null
  }
  
  $go.Add_Click({
      $selectedRow = $dataGridView.CurrentRowIndex
  write-host $selectedRow
  })
  
  [void]$form.ShowDialog() 
  </code></pre>
  
  <p>It simply gets the Process Name, ID, etc. properties and puts them into pre-defined headers in a <code>DataGridView</code>.</p>
  
  <p>My problem is that I want to see the row I've clicked on via <code>$selectedRow = $dataGridView.CurrentRowIndex</code> and output it to the console. Instead, when the 'Select' button is pushed, a blank string is output to the terminal.</p>