winforms - PowerShell DataGridView 复选框行单元格值
问题描述
这是检查复选框是否为真 winforms DataGridView 的功能:
function Install {
param (
# OptionalParameters
)
for($i=0;$i -lt $getAppsDataGrid.RowCount;$i++){
if($getAppsDataGrid.Rows[$i].Cells[3].Value -eq $true)
{
$i
$getAppsDataGrid.Rows[$i].Cells[$i].Value
write-host "cell #$i is checked"
#uncheck it
#$datagridview1.Rows[$i].Cells['exp'].Value=$false
}
else
{
#check it
#$datagridview1.Rows[$i].Cells['exp'].Value=$true
write-host "cell #$i is not-checked"
}
}
}
到目前为止,这是有效的。但我想要当前行的单元格值。$getAppsDataGrid.Rows[$i].Cells[1].Value
在此功能中不起作用。但在此功能之外它可以工作。还有其他东西在这里没有显示,比如 current var $i
。除了“单元 $i 已检查/未检查”之外的所有内容都被忽略
输出:
cell #0 is checked
cell #1 is checked
cell #2 is checked
cell #3 is not-checked
cell #4 is not-checked
cell #5 is not-checked
cell #6 is not-checked
cell #7 is not-checked
cell #8 is not-checked
cell #9 is not-checked
cell #10 is not-checked
cell #11 is not-checked
解决方案
将某些内容写入主机和将其写入输出(或从函数返回)之间是有区别的。
当您使用Write-output $i
orreturn $i
或$i
您将 $i 添加到输出流或函数的结果时。调用函数时,如果将结果捕获到变量中,则不会打印输出。
看这个例子:
function GetEvens {
for($i=0;$i -lt 10;$i++){
if($i%2 -eq 0)
{
$i
write-host "#$i is even"
}
else
{
write-host "#$i is odd"
}
}
}
$evens = GetEvens
它捕获 $evens 中的偶数输出(返回值),但在主机中写入字符串“#i is odd”或“#i is even”。
推荐阅读
- java - 按枚举流 API 组
- javascript - 使用当前脚本路径在脚本中导入 css 文件
- java - RenameTo 似乎随机失败
- csv - Julia 错误地使用科学记数法导入 CSV
- laravel - laravel 背包只显示不禁用元素
- quantum-computing - Q#如何在不破坏量子位状态的情况下读取它?
- ios - CAAnimation - 对“变换”的错误解释?
- swift - 使用 Swift 更改 UITableView 的选定单元格
- c++ - ld: 找不到 -lGL 错误的库
- android - 如何在 recyclerview 适配器和活动中应用 rxjava?