PowerShell的:选择DataGridView的行 [英] Powershell: Selecting DataGridView Row
问题描述
到目前为止,我有这个code。
So far I have this 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()
这只是获取进程名称,ID等特性,并将它们放入pre定义的标题在 DataGridView的
。
我的问题是,我想看看我通过 $ selectedRow = $ dataGridView.CurrentRowIndex
点击该行并输出到控制台。相反,当选择按钮被按下时,一个空白的串输出到所述终端。
My problem is that I want to see the row I've clicked on via $selectedRow = $dataGridView.CurrentRowIndex
and output it to the console. Instead, when the 'Select' button is pushed, a blank string is output to the terminal.
推荐答案
您也可以用得到的行索引:
You can also get the row index with:
$dataGridView.CurrentCell.RowIndex
或
$dataGridView.SelectedRows[0].Index
您可能还需要电网多选属性设置为$ false。目前,它允许多行选择。另一个要考虑的是设置SelectionMode属性设置为FullRowSelect。当填充网格被选择的第一列,而不是整个行
You may also want to set the grid MultiSelect property to $false. Currently it allows multiple rows selection. Another thing to consider is setting the SelectionMode property to 'FullRowSelect'. When the grid is populated the first column is selected, not the whole row.
这篇关于PowerShell的:选择DataGridView的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!