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.
Locked
hrlarsen
Posts: 28
Joined: Tue Jul 24, 2018 8:36 pm

Listview alphabetical a-z Ascending and Descending

Post by hrlarsen » Sat May 11, 2019 3:35 am

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.

User avatar
jvierra
Posts: 13798
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Listview alphabetical a-z Ascending and Descending

Post by jvierra » Sat May 11, 2019 7:22 am

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

See: https://docs.microsoft.com/en-us/dotnet ... work-4.7.2

User avatar
jvierra
Posts: 13798
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Listview alphabetical a-z Ascending and Descending

Post by jvierra » Sat May 11, 2019 8:05 am

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 19 times

Locked