Defining Selection Sets
When creating multiple views and controls, you can define sets of objects that are referred to as
selection sets. A selection set enables you to define the objects one time, without having to define
them repeatedly for each view or control. Typically, selection sets are used when you have a set of
related .NET objects. For example, The FileSystem
formatting file (FileSystem.format.ps1xml)
defines a selection set of the file system types that several views use.
Where Selection Sets are Defined and Referenced
You define selection sets as part of the common data that can be used by all the views and controls defined in the formatting file. The following example shows how to define three selection sets.
<Configuration>
<SelectionSets>
<SelectionSet>...</SelectionSet>
<SelectionSet>...</SelectionSet>
<SelectionSet>...</SelectionSet>
</SelectionSets>
</Configuration>
You can reference a selection sets in the following ways:
Each view has a
ViewSelectedBy
element that defines which objects are displayed by using the view. TheViewSelectedBy
element has aSelectionSetName
child element that specifies the selection set that all the definitions of the view use. There is no restriction on the number of selection sets that you can reference from a view.In each definition of a view or control, the
EntrySelectedBy
element defines which objects are displayed by using that definition. Typically a view or control has only one definition so the objects are defined by theViewSelectedBy
element. TheEntrySelectedBy
element of the definition has aSelectionSetName
child element that specifies the selection set. If you specify the selection set for a definition, you cannot specify any of the other child elements of theEntrySelectedBy
element.In each definition of a view or control, the
SelectionCondition
element can be used to specify a condition for when the definition is used. TheSelectionCondition
element has aSelectionSetName
child element that specifies the selection set that triggers the condition. The condition is triggered when any of the objects defined in the selection set are displayed. For more information about how to set these conditions, see Defining Conditions for when Data is Displayed.
Selection Set Example
The following example shows a selection set that is taken directly from the FileSystem
formatting
file provided by Windows PowerShell. For more information about other Windows PowerShell formatting
files, see Windows PowerShell Formatting Files.
<SelectionSets>
<SelectionSet>
<Name>FileSystemTypes</Name>
<Types>
<TypeName>System.IO.DirectoryInfo</TypeName>
<TypeName>System.IO.FileInfo</TypeName>
<TypeName>Deserialized.System.IO.DirectoryInfo</TypeName>
<TypeName>Deserialized.System.IO.FileInfo</TypeName>
</Types>
</SelectionSet>
</SelectionSets>
The previous selection set is referenced in the ViewSelectedBy
element of a table view.
<ViewDefinitions>
<View>
<Name>Files</Name>
<ViewSelectedBy>
<SelectionSetName>FileSystemTypes</SelectionSetName>
</ViewSelectedBy>
<TableControl>...</TableControl>
</View>
</ViewDefinitions>
XML Elements
There is no limit to the number of selection sets that you can define. The following XML elements are used to create a selection set.
The SelectionSets element defines the sets of .NET objects that are referenced by the views and controls of the formatting file.
The SelectionSet element defines a single set of .NET objects.
The Name element specifies the name that is used to reference the selection set.
The Types element specifies the .NET types of the objects of the selection set. (Within formatting files, objects are specified by their .NET type.)
The following XML elements are used to specify a selection set.
The following element specifies the selection set to use in all the definitions of the view:
The following elements specify the selection set used by a single view definition:
The following elements specify the selection set used by common and view control definitions:
The following elements specify the selection set used when you define which object to expand:
The following elements specify the selection set used by selection conditions.
SelectionSetName Element for SelectionCondition for Controls for Configuration (Format)
SelectionSetName Element for SelectionCondition for Controls for View (Format)
SelectionSetName Element for SelectionCondition for CustomControl for View (Format)
SelectionSetName Element for SelectionCondition for EntrySelectedBy for EnumerableExpansion (Format)
SelectionSetName Element for SelectionCondition for EntrySelectedBy for ListEntry (Format)
SelectionSetName Element for SelectionCondition for EntrySelectedBy for TableControl (Format)
SelectionSetName Element for SelectionCondition for EntrySelectedBy for WideEntry (Format)
SelectionSetName Element for SelectionCondition for GroupBy (Format)