winforms - 在 DataGridView 中显示表格(在表单内部)
问题描述
我正在尝试在DataGridView
表单中添加一个。表格和DataGridView
显示没有问题,但表格似乎没有正确显示。
这是创建表的函数:
function tableCreator(){
$script:statusTable = @()
$txtPath = $script:targetName
Get-Content $txtPath | % {
$script:statusTable += New-Object -TypeName PSObject -Property @{
Computer = "$_";
Connection = "NA";
Status = "NA"
}
}
#$script:statusTableLength = $script:statusTable.Length
}
这是DataGridView
对象:
$script:statusOutput = New-Object System.Windows.Forms.DataGridView #creating the text box System.Windows.Forms.TextBox
$script:statusOutput.Location = New-Object System.Drawing.Size(20,100) #location of the text box (px) in relation to the primary window's edges (length, height)
$script:statusOutput.Size = New-Object System.Drawing.Size(600,350) #the size in px of the text box (length, height)
$script:statusOutput.ScrollBars = "Vertical" #adding scroll bars if required
$script:statusOutput.DataSource = $script:statusTable
这是加载表单并将 设置DataSource
为表的函数:
function runstatusFormFunc {
$reviewprocessForm.Close()
$reviewprocessForm.Visible = $false
tableCreator
testConnection
$script:statusOutput.DataSource = $script:statusTable
$runstatusForm.Add_Shown({$runstatusForm.Activate()})
[void] $runstatusForm.ShowDialog()
}
最终输出如下所示:
解决方案
好吧,我的问题是DataGridView
不接受 Array 作为DataSource
. 它只接受一个 ArrayList。
$Script:statusTable = New-Object System.Collections.ArrayList
代替
$Script:statusTable = @()
解决问题,DataGridView 正确输出对象表
推荐阅读
- google-apps-script - 如何使用 Apps 脚本中的 People API 创建新的联系人组?
- javascript - 在 javascript 中操作对象树
- visual-studio - 是否可以在 Visual Studio 2013 中将本地存储库设置为远程存储库?
- next.js - 即使 getServerSideProps 正确返回,客户端上的错误道具
- amazon-web-services - AWS MediaLive 通道尝试从实时 HLS 输入下载旧段
- node.js - 编译时出错不能在模块外使用导入语句
- html - django 从 HTML 表单中打印复选框的值
- scripting - 在 Mac 上暂停和等待任何鼠标点击的脚本
- spring - 相关的实体总是使用 oneToOne 关系重新保存
- python - 如何在 Flask 中将数组作为响应发送给客户端