簡體   English   中英

PowerShell:如何在CheckListBox中顯示數組

[英]PowerShell: How to display arrays in CheckListBox

我正在嘗試制作導致計算機上不同文件的數組。 然后,我想在一個復選框中顯示數組,因此我可以單擊並從此處打開文件。 該數組可以是靜態的,但是如果我可以動態添加新的東西,那就更好了。

$menulist.DataBindings.DefaultDataSourceUpdateMode = 0
$menulist.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 24
$menulist.Location = $System_Drawing_Point
$menulist.Name = "menulist"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 328
$System_Drawing_Size.Width = 235
$TemplateArray = $template1,$template2;
$template1 = Get-ChildItem -Path C:\Users\$Env:USERNAME\Documents\test.tx
$template2 = Get-ChildItem -Path C:\Users\$Env:USERNAME\Documents\test2.txt
$menulist.Items.AddRange($TemplateArray)
$menulist.Size = $System_Drawing_Size
$menulist.TabIndex = 7

在我們仍在討論您的需求時,我會猜測:

$TemplateArray = $template1,$template2;
$template1 = Get-ChildItem -Path C:\Users\$Env:USERNAME\Documents\test.tx
$template2 = Get-ChildItem -Path C:\Users\$Env:USERNAME\Documents\test2.txt

上面的通知-在聲明$template1$template2之前已使用它們。 您可能會在其中得到兩個空字符串。 相反,請首先初始化變量:

$template1 = Get-ChildItem -Path C:\Users\$Env:USERNAME\Documents\test.tx
$template2 = Get-ChildItem -Path C:\Users\$Env:USERNAME\Documents\test2.txt
$TemplateArray = $template1,$template2;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM