Product: PowerShell Studio 2021 (64 Bit)
Build: v5.8.194
OS: Windows 10 Education (64 Bit)
Build: v10.0.19041.0
Hello,
how can all rows be removed from a datagridview, without the column header? $dataGridView.DataSource = $null remove the header too
Remove all rows from datagridview except column header
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- DanielLeber
- Posts: 20
- Last visit: Thu May 18, 2023 8:36 am
- DanielLeber
- Posts: 20
- Last visit: Thu May 18, 2023 8:36 am
Re: Remove all rows from datagridview except column header
The $dataGridView.Rows.Clear() not really works. Exception calling "Clear" with "0" argument(s): "Cannot clear this list." Do you have another idea?
- Attachments
-
- 29-09-_2021_20-00-55.png (50.1 KiB) Viewed 6258 times
- DanielLeber
- Posts: 20
- Last visit: Thu May 18, 2023 8:36 am
Re: Remove all rows from datagridview except column header
Inside the ConvertTo-DataTable function is a method, to clear the datatable object
I would like to clear all gridview entries when the ComboBox index changes, but keep the header. How can I realize this?Re: Remove all rows from datagridview except column header
No. You have to clear the DataTable object with is the object attached to the DataSource property. Of course, that depends on how you created the DataGridView and loaded it. There are many ways to load a DataGridView control.
- DanielLeber
- Posts: 20
- Last visit: Thu May 18, 2023 8:36 am
Re: Remove all rows from datagridview except column header
I load the DataGridView control as a Job.
Have you an example for me how can I clear it from the $ComboBoxPrintServer_SelectedIndexChanged = {} ?
I'm kind of at a loss here
Have you an example for me how can I clear it from the $ComboBoxPrintServer_SelectedIndexChanged = {} ?
I'm kind of at a loss here
Re: Remove all rows from datagridview except column header
That's easy, just clear it. Remember the datatable should not be assigned via an Update-DataGridView as that would be redundant. Just assign it as the DataSource.
- DanielLeber
- Posts: 20
- Last visit: Thu May 18, 2023 8:36 am
Re: Remove all rows from datagridview except column header
It's easy when you know how it works. Please, give me a specific example
Re: Remove all rows from datagridview except column header
Just "Clear()" the DataSource. Why is that so hard? You have a table referenced by the DataSource so just call "Clear()" on the referenced object through the DataSource reference.