使用 Powershell 计算 DataGridView 中的可见行



在我使用$DataGridView1.Rows[$row.Index].Visible = $false隐藏一些行之后,我需要计算现在有多少行可见。

如果我使用$DataGridView1.Rows.GetRowCount.ToString()

我得到这个结果:

int GetRowCount(System.Windows.Forms.DataGridViewElementStates includeFilter)

所以,如果我使用$DataGridView1.Rows.GetRowCount($DataGridViewElementStates.Visible)

我希望我的 DataGridView 中有许多可见行,但它返回一个异常:

Cannot convert argument "includeFilter", with value: "", for "GetRowCount" 
to type "System.Windows.Forms.DataGridViewElementStates": "Cannot convert null 
to type "System.Windows.Forms.DataGridViewElementStates" due to enumeration 
values that are not valid. Specify one of the following enumeration values and 
try again. The possible enumeration values are 
"None,Displayed,Frozen,ReadOnly,Resizable,ResizableSet,Selected,Visible"."

我做错了什么?

如错误所示,您需要提供类型为System.Windows.Forms.DataGridViewElementStates的值:

$DataGridView1.Rows.GetRowCount([System.Windows.Forms.DataGridViewElementStates]::Visible)

最新更新