Powershell DataGridViewButtonColumn:按钮文本自定义

时间:2017-02-07 04:20:10

标签: powershell

[在此处输入图像说明] [1] [1]:https://i.stack.imgur.com/N7AhL.png您好我在自定义表单中使用Gridview输出我卡在上面的图像标签:UninstallFunction:卸载我的代码:#Start-Process Powershell -verb runas #Load Windows Forms assembly [void] [System.Reflection.Assembly] :: LoadWithPartialName(“System.Windows.Forms”)[void] [System.Windows.Forms.Application] :: EnableVisualStyles()#创建一个GUI $ form = New-Object System.Windows.Forms.Form $ form.Size = New-Object System.Drawing.Size(920,500)$ form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle] :: Fixed3D $ form。 StartPosition = [System.Windows.Forms.FormStartPosition] :: CenterScreen $ dataGridView = New-Object System.Windows.Forms.DataGridView $ dataGridView.Size = New-Object System.Drawing.Size(900,400)$ button = New-Object System .Windows.Forms.Button $ button.Location = New-Object System.Drawing.Size(400,420)$ button.Size = New-Object System.Drawing.Size(75,25)$ button.text =“Uninstall”$ form .Controls.Add($ button)$ form.Controls.Add($ d ataGridView)#选择合适的列$ dataGridView.Columns.Insert(0,(New-Object System.Windows.Forms.DataGridViewButtonColumn))$ dataGridView.ColumnCount = 9 $ dataGridView.ColumnHeadersVisible = $ true $ dataGridView.Columns [0] .Name =“卸载”$ dataGridView.Columns [1] .Name =“Description”$ dataGridView.Columns [2] .Name =“IdentifyingNumber”$ dataGridView.Columns [3] .Name =“Name”$ dataGridView.Columns [4] .Name =“Vendor”$ dataGridView.Columns [5] .Name =“Version”$ dataGridView.Columns [6] .Name =“Caption”$ dataGridView.Columns [7] .Name =“InstallLocation”$ dataGridView.Columns。 Insert(8,(New-Object System.Windows.Forms.DataGridViewButtonCell))$ dataGridView.Columns [0] .width = 50 $ dataGridView.Columns [1] .width = 200#获取项目列表< #Get- WmiObject -Class Win32_Product | foreach {$ dataGridView.Rows.Add($ .Check,$ .Description,$ .IdentifyingNumber,$ .Name,$ .Vendor,$ .Version,$ .Caption,$ .InstallLocation)| out-null}#> #刷新函数gridClick(){$ dataGridView.Text ='删除所选行'$ rowIndex = $ dataGridView.CurrentRow.Index $ columnIndex0 = $ dataGridView.ColumnIndex + 1 $ columnIndex1 = $ dataGridView.ColumnIndex + 2 $ columnIndex2 = $ dataGridView。 ColumnIndex + 3 $ columnIndex3 = $ dataGridView.ColumnIndex + 4 $ columnIndex5 = $ dataGridView.ColumnIndex + 5#Write-Host $ rowIndex#Write-Host $ columnIndex0#Write-Host $ dataGridView.Rows [$ rowIndex] .Cells [0] .value Write-Host $ dataGridView.Rows [$ rowIndex] .Cells [$ columnIndex0] .value Write-Host $ dataGridView.Rows [$ rowIndex] .Cells [$ columnIndex1] .value Write-Host $ dataGridView.Rows [$ rowIndex ] .Cells [$ columnIndex5] .value#$ IdentifyNumber = $ dataGridView.Rows [$ rowIndex] .Cells [$ ClassKey] .value#$ Name = $ dataGridView.Rows [$ rowIndex] .Cells [$ columnIndex0] .value# $ classKey ='IdentifyingNumber = $ IdentifyingNumber.value,Name = $ Name.value,Version = $ Version.value'#Write-Host $ classKey#([wmi]“\ $ server \ root \ cimv2:Win32_Product。$ classKey” ).uninstall()} $ Uninstall = $ dataGrid View.Add_CellMouseClick({gridClick})#显示表单[void] $ form.ShowDialog()

我想将标签添加到命令框。 (请参阅随附的屏幕截图)这是一个带有GridView输出的自定义表单,其中每列需要添加一个按钮。我需要在按钮中放置一个标签。

1 个答案:

答案 0 :(得分:0)

您可以尝试在网格点击功能中更改值:

 $dataGridView.Rows[$rowIndex].Cells[0].Value = "test value"