listview sorting by clicking on column heading

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 5 years and 5 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
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

listview sorting by clicking on column heading

Post by jsira2003@yahoo.com »

I know to sort in datagridview by sorting on column heading is difficult. It is easier to do this in listview? Also with listview can i just add a datasource with any array such as:

$lvtable.datasource = $myarray

thanks,
John
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: listview sorting by clicking on column heading

Post by jvierra »

A DataGridView based on a table source is completely sortable on any column by default.

The ListView control is not data enabled for items. Sorts on a ListView have to be custom coded.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: listview sorting by clicking on column heading

Post by jvierra »

Example of sort and filter
Attachments
Demo-DGVSortFormat.psf
(17.58 KiB) Downloaded 125 times
User avatar
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

Re: listview sorting by clicking on column heading

Post by jsira2003@yahoo.com »

Well I got it working 90%. My only issue is I have a couple columns with numbers. They were declared as float and instead of sorting numerically, they sort as string text. Any idea why a couple of my columns do not sort correctly? All my columns are floats.

thank you,
John
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: listview sorting by clicking on column heading

Post by jvierra »

You have to make the columns into numbers and not text. Only numeric values will sort as numbers.

Note that my example sorts the "length" column correctly.
This topic is 5 years and 5 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