Listview alphabetical a-z Ascending and Descending

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 4 years and 11 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
hrlarsen
Posts: 31
Last visit: Sun Dec 18, 2022 1:47 pm

Listview alphabetical a-z Ascending and Descending

Post by hrlarsen »

Listview form how to sort it alphabetical a-z
What I mean is Ascending and Descending.

I will try to give more information about her what I am after.

First we create the standard ListView Form size ect I am not gonna list all about that.
# ListView form
$ListView = New-Object System.Windows.Forms.ListView
# A details list
$ListView.View = [System.Windows.Forms.View]::Details

Then we have the 2 header Columns like this
# Add columns to the ListView
$ListView.Columns.Add("first")
$ListView.Columns.Add("secound")

Result output:
first | secound


# Next we can add items (leftside) and Subitems (rightside)
$ListViewItem = New-Object System.Windows.Forms.ListViewItem("text1")
$ListViewItem.Subitems.Add("text2")

Result output:
first | secound
text1| text2
And we can create more under
eeeee| dddddd
sssssss| wwww



# We can sort the "first" $ListView.Columns A-Z like this when the form start or via button click
$ListView.Sorting ='Ascending';

But here is the problem, how do I unly sort "secound" Columns
So it goes like this.
a
b
c
d
And so on.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Listview alphabetical a-z Ascending and Descending

Post by jvierra »

You can only sort one column - the "Item" column.

See: https://docs.microsoft.com/en-us/dotnet ... work-4.7.2
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Listview alphabetical a-z Ascending and Descending

Post by jvierra »

Here is the sample of how the "sorting" property of a ListView works.

Run the attached PS1 to see the demo. Note that "None" does nothing.
Attachments
Demo-ListViewSorting.ps1
(3.12 KiB) Downloaded 205 times
This topic is 4 years and 11 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