Powershell: Selecting DataGridView Row


SUBMITTED BY: Guest

DATE: Nov. 14, 2013, 7:08 a.m.

FORMAT: Text only

SIZE: 1.2 kB

HITS: 955

  1. Powershell: Selecting DataGridView Row
  2. $form = New-Object System.Windows.Forms.Form
  3. $form.Size = New-Object System.Drawing.Size(900,600)
  4. $dataGridView = New-Object System.Windows.Forms.DataGridView
  5. $dataGridView.Size=New-Object System.Drawing.Size(800,400)
  6. $go = New-Object System.Windows.Forms.Button
  7. $go.Location = New-Object System.Drawing.Size(300,450)
  8. $go.Size = New-Object System.Drawing.Size(75,23)
  9. $go.text = "Select"
  10. $form.Controls.Add($go)
  11. $form.Controls.Add($dataGridView)
  12. $dataGridView.ColumnCount = 4
  13. $dataGridView.ColumnHeadersVisible = $true
  14. $dataGridView.Columns[0].Name = "Name"
  15. $dataGridView.Columns[1].Name = "ID"
  16. $dataGridView.Columns[2].Name = "Description"
  17. $dataGridView.Columns[3].Name = "Memory"
  18. $dataGridView.Columns[0].width = 240
  19. get-process | foreach{
  20. $dataGridView.Rows.Add($_.Name,$_.ID,$_.Description,$_.WorkingSet)|out-null
  21. }
  22. $go.Add_Click(
  23. {
  24. $selectedRow = $dataGridView.CurrentRowIndex
  25. write-host $selectedRow
  26. })
  27. [void]$form.ShowDialog()
  28. $dataGridView.CurrentCell.RowIndex
  29. $dataGridView.SelectedRows[0].Index

comments powered by Disqus