none
WPF ListView Column Sort System.Windows.Controls

    Question

  • Xaml:

    <ListView Name="WindowsServicesListView"  FontWeight="Normal" Background="#F0F0F0"
    HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="11" 
    Margin="5,0,0,0" Width="740" Height="280" >
    <ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
    <Setter Property="Margin" Value="-5,0,-5,0" />
    </Style>
    </ListView.ItemContainerStyle>
    <ListView.View>
    <GridView AllowsColumnReorder = "True" >
    <GridViewColumn Header="Name"  Width = "185" DisplayMemberBinding="{Binding SVCName}" />
    <GridViewColumn Header="Status"  Width = "185" DisplayMemberBinding="{Binding Status}" />
    <GridViewColumn Header="StartupType"  Width = "185" DisplayMemberBinding="{Binding StartupType}" />
    <GridViewColumn Header="Log on as"  Width = "185" DisplayMemberBinding="{Binding Logon}" />
    </GridView>
    </ListView.View>
    </ListView>

    PowerShell code:

    $ServerSelectButton.Add_click({

        # Input Server
        $serverSelected = $ServerNameTextbox.Text

        $errMsgList = @()

        # See if the server is online
        if (-not(Test-Connection -ComputerName $serverSelected -Count 1 -Quiet))
        {
            $errMsgList += "Server -> [$serverSelected] does not exist or is not online"
        }
        else
        {
            $WindowsServicesListView.Items.Clear() # Clear the ListView

            # Target servers
            $services = Get-WmiObject win32_service -ComputerName $serverSelected

            # List the services
            foreach ($service in $services)
            {      
                $WindowsServicesListView.Items.Add([pscustomobject]@{SVCName="$($service.name)";Status="$($service.state)";StartupType="$($service.startmode)";Logon="$($service.StartName)"})
            }
        }

        # Error 
        if ($errMsgList.Count -gt 0)
        {   # Input is not valid
            DisplayErrorMsgBox -Message ($errMsgList | Out-String)
            return
        }   

    })

    I am trying to use sort by click on the column header but I can't seem to find solution

    Could someone please help?

                       
    Thursday, December 6, 2018 4:42 PM

Answers

All replies