PowerShell -Working With DataGridView- WinForm and DataTable

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
jvierra
Posts: 14550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by jvierra »

Not enough information. You need to post the URL and the code you are using to get the values.

probles40
Posts: 15
Joined: Sat Apr 11, 2020 6:05 pm

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by probles40 »

Sure, I missed this one. here is the url, 'https://psu.box.com/shared/static/jf36o ... w4y708.rss'

jvierra
Posts: 14550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by jvierra »

The link you posted is invalid.

probles40
Posts: 15
Joined: Sat Apr 11, 2020 6:05 pm

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by probles40 »

jvierra, the link goes to a server that probably is not open to the public. If you tell me what commands to run on the xml file, I can return the file structure.

jvierra
Posts: 14550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by jvierra »

Post the XML for one RSS entry.

probles40
Posts: 15
Joined: Sat Apr 11, 2020 6:05 pm

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by probles40 »

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>IT Alerts</title>
<link>https://*/sp?id=service_status</link>
<description>IT Alerts for the last 7 days, plus Planned Maintenance for the next 5 days.</description>
<lastBuildDate>21 Apr 2020 11:54:56 -0400</lastBuildDate>
<language>en-us</language>
<generator>IT Alerts 1.0</generator>
<image>
<url>https://*/logosignature.png</url>
<title>IT Alerts</title>
<link>https://*/sp?id=service_status</link>
</image>
<atom:link href="https://*/shared/static/jf36ohodxnw7oemghsau1t7qb0w4y708.rss" rel="self" type="application/rss+xml" /><item>
<title>Office365 Email and Calendars Degradation</title>
<link><![CDATA[https://*/sp?id=service_status&service=7119bb164fd68b80d0f9e3414210c77a]]></link>
<pubDate>14 Apr 2020 14:46:29 -0400</pubDate>
<guid isPermaLink="false">1ef68ac41b401cd07746766dcc4bcb35</guid>
<description><![CDATA[<p><strong>IT continues to address issues as they arise. You can find workaround instructions at <a href="https://*/sp?id&#61;kb_article_view&amp;sysparm_article&#61;KB0013571" rel="nofollow">https://*/sp?id&#61;kb_article_view&amp;sysparm_article&#61;KB0013571</a> (KB0013571).</strong></p>
<p> </p>
<p><strong>People and Locations Impacted:</strong><br />All students, faculty, &amp; staff at all locations with confirmation messages sent to Office 365<br /><br /><strong>IT Service(s) Impacted:</strong><br />lists.psu.edu<br /><br /><strong>Date and Time:</strong><br />Issue began on 03/31/20 and Penn State IT is working with the vendor (Microsoft) on a resolution.<br /><br /><strong>Notes:</strong><br />You can find workaround instructions at <a href="https://*/sp?id&#61;kb_article_view&amp;sysparm_article&#61;KB0013571" rel="nofollow">https://*/sp?id&#61;kb_article_view&amp;sysparm_article&#61;KB0013571</a> (KB0013571).<br /><br /><strong>Technical Information:</strong><br />Office 365/Microsoft ATP is deep scanning listserv confirmation links which is causing messages to be approved without the moderator actually clicking the message to approve. This alert will be updated as new information becomes available. All IT users can view additional details in ServiceNow.<br /><br /><strong>Public Contact for this Alert:</strong><br />IT Service Desk<br />itservicedesk@*<br />888-888-HELP</p>]]></description>
</item>
</channel>
</rss>

probles40
Posts: 15
Joined: Sat Apr 11, 2020 6:05 pm

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by probles40 »

jvierra, with so many rows presented to the end-user, what is the command to collapse a row or expand the row if the user wants to read more

jvierra
Posts: 14550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by jvierra »

DataGrids do not have collapsible rows.

probles40
Posts: 15
Joined: Sat Apr 11, 2020 6:05 pm

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by probles40 »

instead of using datagrid, i could use convertto-html or something similar. RSS alerts could come down in five or six in any given moment. People not going to like scrolling through pages.

probles40
Posts: 15
Joined: Sat Apr 11, 2020 6:05 pm

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by probles40 »

Hi, I made a complete adjustment to the original script. It is working and building on html code. However, I would love to have the title for each of the event on top of the description, and to use collapsible option so only shows the event title. And, if the end-user wants to read the topic or title, to have the option to click on the cell with the title and to be able to expand the road.
  1. cls
  2.  
  3. function GenerateForm {
  4.  
  5.  
  6.  
  7. Add-Type -AssemblyName System.Windows.Forms
  8.  
  9. Add-Type -AssemblyName System.drawing
  10.  
  11.  
  12.  
  13. #Form Setup
  14.  
  15. $form1 = New-Object System.Windows.Forms.Form
  16.  
  17. $TabControl = New-object System.Windows.Forms.TabControl
  18.  
  19. $AlertsPage = New-Object System.Windows.Forms.TabPage
  20.  
  21.  
  22.  
  23. $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
  24.  
  25.  
  26.  
  27. #Form Parameter
  28.  
  29. $form1.Text = "Computer User Preferences and Utilities"
  30.  
  31. $form1.Name = "form1"
  32.  
  33. $form1.DataBindings.DefaultDataSourceUpdateMode = 0
  34.  
  35. $form1.StartPosition = "CenterScreen"
  36.  
  37. $System_Drawing_Size = New-Object System.Drawing.Size
  38.  
  39. $System_Drawing_Size.Width = 775
  40.  
  41. $System_Drawing_Size.Height = 490
  42.  
  43. $form1.ClientSize = $System_Drawing_Size
  44.  
  45.  
  46.  
  47. #Tab Control
  48.  
  49. $tabControl.DataBindings.DefaultDataSourceUpdateMode = 0
  50.  
  51. $System_Drawing_Point = New-Object System.Drawing.Point
  52.  
  53. $System_Drawing_Point.X = 30
  54.  
  55. $System_Drawing_Point.Y = 65
  56.  
  57. $tabControl.Location = $System_Drawing_Point
  58.  
  59. $tabControl.Name = "tabControl"
  60.  
  61. $System_Drawing_Size = New-Object System.Drawing.Size
  62.  
  63. $System_Drawing_Size.Height = 405
  64.  
  65. $System_Drawing_Size.Width = 725
  66.  
  67. $tabControl.Size = $System_Drawing_Size
  68.  
  69. $form1.Controls.Add($tabControl)
  70.  
  71.  
  72.  
  73. #Eventlog Page
  74.  
  75. $AlertsPage.DataBindings.DefaultDataSourceUpdateMode = 0
  76.  
  77. $AlertsPage.UseVisualStyleBackColor = $True
  78.  
  79. $AlertsPage.Name = "AlertPage"
  80.  
  81. $AlertsPage.Text = "Alerts”
  82.  
  83. $tabControl.Controls.Add($AlertsPage)
  84.  
  85.  
  86.  
  87. $head = @"
  88.  
  89. <style>
  90.  
  91. body { background-color:#dddddd;
  92.  
  93.        font-family:Tahoma;
  94.  
  95.        font-size:10pt; }
  96.  
  97. td, th { border:1px solid black;
  98.  
  99.          border-collapse:collapse; }
  100.  
  101. th { color:white;
  102.  
  103.      background-color:black; }
  104.  
  105. table, tr, td, th { padding: 2px; margin: 0px }
  106.  
  107. table {width:100% margin-left:0px; }
  108.  
  109. </style>
  110.  
  111.  
  112.  
  113. "@
  114.  
  115.  
  116.  
  117. $webBrowser1 = new-object system.net.webclient
  118.  
  119. $rssFeed = [xml]$webBrowser1.DownloadString('https://*/jf36ohodxnw7oemghsau1t7qb0w4y708.rss')
  120.  
  121. $items = $rssFeed.rss.channel.item |
  122.  
  123.    ForEach-Object {
  124.  
  125.        [PSCustomObject]@{
  126.  
  127.            Date = [datetime]$_.pubDate
  128.  
  129.            Title = $_.title
  130.  
  131.             Description = [string]$_.description.innertext -replace '<br ?/?>',[System.Environment]::NewLine -replace '<[^>]+>'
  132.  
  133.            #Category = [string]$_.description.innertext -replace '<br ?/?>',[System.Environment]::NewLine -replace '<[^>]+>'
  134.  
  135.        }
  136.  
  137. }
  138.  
  139. $items |Sort-Object Date -Descending | ConvertTo-Html -Head $head | out-File -filepath "c:\Alerts\alert.html"
  140.  
  141. $webBrowser1 = New-Object System.Windows.Forms.WebBrowser
  142.  
  143. $webBrowser1.Location = New-Object System.Drawing.Size(10,60)
  144.  
  145. $webBrowser1.Size = New-Object System.Drawing.Size(690,300)
  146.  
  147. $webBrowser1.URL= "c:\Alerts\alert.html"
  148.  
  149. $AlertsPage.Controls.Add($webBrowser1)
  150.  
  151.  
  152.  
  153. #Save the initial state of the form
  154.  
  155. #Init the OnLoad event to correct the initial state of the form
  156.  
  157. #Show the Form
  158.  
  159. $form1.ShowDialog()| Out-Null
  160.  
  161. } #End Function
  162.  
  163. GenerateForm

Locked