2017-05-11 144 views
0

我已經嘗試了下面的代碼來顯示ListViewbox中的輸出。但我無法在框中顯示任何輸出。如何以Powershell GUI ListViewbox的表格格式顯示輸出?

Add-Type -AssemblyName System.Windows.Forms 

$Form = New-Object system.Windows.Forms.Form 
$Form.Text = "Form" 
$Form.TopMost = $true 
$Form.Width = 696 
$Form.Height = 323 

$button2 = New-Object system.windows.Forms.Button 
$button2.Text = "Go" 
$button2.Width = 60 
$button2.Height = 30 
$button2.Add_Click({ 
     $listView3.Text = Get-Process | Out-String 
}) 
$button2.location = new-object system.drawing.point(238,70) 
$button2.Font = "Microsoft Sans Serif,10" 
$Form.controls.Add($button2) 

$listView3 = New-Object system.windows.Forms.ListView 
$listView3.Text = "listView" 
$listView3.Width = 330 
$listView3.Height = 600 
$listView3.location = new-object system.drawing.point(269,146) 
$Form.controls.Add($listView3) 

[void]$Form.ShowDialog() 
$Form.Dispose() 

我需要在列表框中顯示的表格式輸出以及..在此先感謝....

回答

0

ListView控件不控制所顯示的內容的.text財產,你需要添加項目。假設你要在列表中顯示的進程名,而不是:

$listView3.Text = Get-Process | Out-String 

嘗試:

Get-Process | %{$listView3.Items.Add($_.processname)} 

要添加子項目你需要做這樣的事情:

Get-Process | %{$item = $listView3.Items.Add($_.processname);$item.SubItems.Add($_.Handles)} 
+0

謝謝你,我現在能夠查看輸出。此外,我需要顯示在格式表.. –

+0

嘗試'$ listView3.View =「詳細信息」'。您可能需要添加您想要作爲子項目查看的列。我會給我的答案添加一個例子。 –