WPF PowerShell Click on column name to sort

Welcome Forums General PowerShell Q&A WPF PowerShell Click on column name to sort

Viewing 2 reply threads
  • Author
    Posts
    • #129969
      Jay
      Participant
      Topics: 4
      Replies: 1
      Points: 54
      Rank: Member

      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 clicking on the column header but I can’t seem to find solution

      I was only able to find c# code..

       

      https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/how-to-sort-a-gridview-column-when-a-header-is-clicked

    • #130380
      Participant
      Topics: 12
      Replies: 1618
      Points: 2,543
      Helping Hand
      Rank: Community Hero
      • #130407
        Jay
        Participant
        Topics: 4
        Replies: 1
        Points: 54
        Rank: Member

        Thank you Rob, but I need the code in PowerShell syntax..

    • #130482
      Participant
      Topics: 2
      Replies: 1013
      Points: 2,093
      Helping Hand
      Rank: Community Hero

      Form object control is in the hands of the form code, not PS.

      https://blog.thoughtstuff.co.uk/2012/01/wpf-sorting-gridview-columns-by-clicking-headers

      Otherwise, understand that PS, extract data input or puts data into form elements, it does not control the form elements themselves.

      If you want PS code to do this, then it has to clear / refresh the form element on that click event that calls your PS code that gets the data, pre-sorted then send back to the form element. This of course this sort of thing results in element flicker, meaning, the clear and replace is obvious, vs just sort in place via form code, which Rob is pointing to.

Viewing 2 reply threads
  • The topic ‘WPF PowerShell Click on column name to sort’ is closed to new replies.