PowerShell – DataGridView – Table Properties

Welcome Forums General PowerShell Q&A PowerShell – DataGridView – Table Properties

Viewing 1 reply thread
  • Author
    Posts
    • #218340
      Participant
      Topics: 2
      Replies: 0
      Points: 25
      Rank: Member

      I am looking to improve the layout and sorting options of my datagridview table. The code, shared below, is working and it is presenting the information correctly. However, my limited powershell skills does not help me on making some improvements such as adding sorting option for the first “date-time” column, add color to the rows based on the alert message (information (white), degradation, disruption (red)), and adding an option to shrink or expand the rows. Please, Please, if you have a suggestion on to improve the code and the goal is still achieved, please teach me with an example what to change.Thanks!

      $outputBox040 = Invoke-WebRequest -Uri ‘https://*.rss’ -OutFile C:\*.rss
      [xml]$Content = Get-Content C:\*.rss
      $Feed = $Content.rss.channel
      $url = foreach ($msg in $Feed.item){
      $commentsPlain = $msg.description.InnerText -replace ‘<br ?/?>’,[System.Environment]::NewLine -replace ‘<[^>]+>’
      [PSCustomObject]@{
      ‘Date-Time’ = [datetime]$msg.pubDate
      ‘Title’ = “$($msg.title), ,
      $($commentsPlain)”
      #’Link’ = $msg.link.InnerText
      #’Comments’ = $commentsPlain
      ‘Category’ = $msg.category
      }
      }

      $list = New-Object System.collections.ArrayList
      $list.AddRange(@($url))
      $outputbox040 = New-Object System.Windows.Forms.DataGridView -Property @{
      Size=New-Object System.Drawing.Size(718,505)
      Location = New-Object System.Drawing.Size(0,1)
      ColumnHeadersVisible = $true
      AutoSizeColumnsMode = ‘DisplayedCellsExceptHeader’
      AutoSizeRowsMode = ‘AllCells’
      AllowUserToDeleteRows = ‘false’
      DefaultCellStyle= @{WrapMode =’True’}
      RowHeadersVisible = $false
      ReadOnly = ‘true’
      DataSource = $list
      }
      $AlertsPage.Controls.Add($outputBox040)

    • #218379
      Participant
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP

      When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to you help making their work twice or more.

      https://social.technet.microsoft.com/Forums/en-US/f4dafd09-525c-41cb-82f1-ad89eb3e862e/powershell-datagridview-table-properties?forum=winserverpowershell

      Thanks

Viewing 1 reply thread
  • You must be logged in to reply to this topic.