ConvertDataset for GridView 'Invalid storage type: DBNull.'

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
This topic is 3 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: ConvertDataset for GridView 'Invalid storage type: DBNull.'

Post by stevens »

Yes I know, I should click the column header, but nothing happens.

>If the DataTable is correctly bound to the table then it is sortable.
How can I check this?
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: ConvertDataset for GridView 'Invalid storage type: DBNull.'

Post by stevens »

Found out what the issue was, I do all kinds of filtering of the dataset, that makes that sorting isn't working anymore.

Load-DataGridView -DataGridView $datagridview1 -Item $($dataset | sort name)
does not work
Load-DataGridView -DataGridView $datagridview1 -Item $dataset

Works fine = sorting works.
However, I do need sorting, where should I sort then?
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: ConvertDataset for GridView 'Invalid storage type: DBNull.'

Post by stevens »

Note: I also use filters

-$dataset = $dataset | Where-Object { $values -notcontains ...
Load-DataGridView -DataGridView $datagridview1 -Item $dataset
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ConvertDataset for GridView 'Invalid storage type: DBNull.'

Post by jvierra »

Which is why I posted to use
$datagridview.DataSounrce = $dt.

You kept many issues hidden which makes it impossible to answer the question. A simple data table assigned as a DataSource is always sortable. I repeat - A single DataTable - not a data set - is always sortable.

Create a dataset and then converting it to something else using the "Load-DataGridView" is not what you asked about and will not work as expected. Why take a DataTable, call it a dataset and then try to convert it into a DataTable? Do you see what you are actually doing by trying to do it this way. It is just doing it three times for no reason.
Also the correct way to filter a DataTable object is the use the "RowFilter" Using Where-Object damages the table structure since it converted it into a set of custom objects.

A DataTable is a very special type of object which supports an extended array of capabilities. When add3ed to a form/control it completes the forms purpose which is to act as a Data management object. Notice how almost all controls have a "DataSource" property. This is because Forms and ADO were designed to work together.

Once you can get an understanding of how this works and how it is intended to be used coding forms will be much easier.

If you are interested, I can show you examples of very complex data bound forms that require very few lines of code to create.
This topic is 3 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked