Example:
Code: Select all
Add-ListViewItem -ListView $listview1 -Items 'Test13' -Group Group1
Code: Select all
Add-ListViewItem -ListView $listview1 -Items 'Test13' -Group Group1
This is a common misunderstanding of what sorting does when sorting unkeyed items. In SQL specifying an “ORDER BY” does not change the order of the data in storage. With controls and in-place sorts the original order is lost after the first sort. This is by design. It would take a special implementation for a ListView to behave differently.Typically items are sorted using the Sorting property, which sorts items based on the item text. To customize the sort order, you must write a class that implements the IComparer interface and set the ListViewItemSorter property to an object of that class. This is useful, for example, when you want to sort items by subitem text. For more information on performing manual sorting of items, see the example for the ListViewItemSorter property.
If the ListView.Sorting property is set to a value other than SortOrder.None or if the ListViewItemSorter property is set, the list is sorted automatically when items are added. Items are not sorted automatically when the label text changes.
If you set sorting before adding the items will be sorted as they are added. If you don’t they will be displayed in the order added.
Changing the sort order will resort the items. Changing the “Sorting” property to “None” will leave the items in the current order. It will not return them to the original order as added.
Code: Select all
function Set-Ascending
{
$listview1.View = 'List'
$listview1.Sorting = 'Ascending'
}
function Set-Descending
{
$listview1.View = 'List'
$listview1.Sorting = 'Descending'
}
function Set-Grouped
{
$listview1.View = 'SmallIcon'
#No Sorting
}