0

After I've used $DataGridView1.Rows[$row.Index].Visible = $false to hide some rows, I need to count how many are visible now.

If I use $DataGridView1.Rows.GetRowCount.ToString()

I get this result:

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

So, if I use $DataGridView1.Rows.GetRowCount($DataGridViewElementStates.Visible)

I would expect a number of the visible rows in my DataGridView, but it returns an exception:

    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"."

What am I doing wrong?

1 Answer 1

3

As the error indicates, you'll need to supply a value of type System.Windows.Forms.DataGridViewElementStates:

$DataGridView1.Rows.GetRowCount([System.Windows.Forms.DataGridViewElementStates]::Visible)
Sign up to request clarification or add additional context in comments.

2 Comments

All I could find about this was related to C#, but I was unable to translate that code into Powershell. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.