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.
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
Last visit: Mon Apr 27, 2020 8:41 am

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by jvierra »

The link you posted is invalid.
probles40
Posts: 15
Last visit: Mon Apr 27, 2020 8:41 am

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by jvierra »

Post the XML for one RSS entry.
probles40
Posts: 15
Last visit: Mon Apr 27, 2020 8:41 am

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
Last visit: Mon Apr 27, 2020 8:41 am

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PowerShell -Working With DataGridView- WinForm and DataTable

Post by jvierra »

DataGrids do not have collapsible rows.
probles40
Posts: 15
Last visit: Mon Apr 27, 2020 8:41 am

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
Last visit: Mon Apr 27, 2020 8:41 am

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. function GenerateForm {
  3.  
  4. Add-Type -AssemblyName System.Windows.Forms
  5. Add-Type -AssemblyName System.drawing
  6.  
  7. #Form Setup
  8. $form1 = New-Object System.Windows.Forms.Form
  9. $TabControl = New-object System.Windows.Forms.TabControl
  10. $AlertsPage = New-Object System.Windows.Forms.TabPage
  11.  
  12. $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
  13.  
  14. #Form Parameter
  15. $form1.Text = "Computer User Preferences and Utilities"
  16. $form1.Name = "form1"
  17. $form1.DataBindings.DefaultDataSourceUpdateMode = 0
  18. $form1.StartPosition = "CenterScreen"
  19. $System_Drawing_Size = New-Object System.Drawing.Size
  20. $System_Drawing_Size.Width = 775
  21. $System_Drawing_Size.Height = 490
  22. $form1.ClientSize = $System_Drawing_Size
  23.  
  24. #Tab Control
  25. $tabControl.DataBindings.DefaultDataSourceUpdateMode = 0
  26. $System_Drawing_Point = New-Object System.Drawing.Point
  27. $System_Drawing_Point.X = 30
  28. $System_Drawing_Point.Y = 65
  29. $tabControl.Location = $System_Drawing_Point
  30. $tabControl.Name = "tabControl"
  31. $System_Drawing_Size = New-Object System.Drawing.Size
  32. $System_Drawing_Size.Height = 405
  33. $System_Drawing_Size.Width = 725
  34. $tabControl.Size = $System_Drawing_Size
  35. $form1.Controls.Add($tabControl)
  36.  
  37. #Eventlog Page
  38. $AlertsPage.DataBindings.DefaultDataSourceUpdateMode = 0
  39. $AlertsPage.UseVisualStyleBackColor = $True
  40. $AlertsPage.Name = "AlertPage"
  41. $AlertsPage.Text = "Alerts”
  42. $tabControl.Controls.Add($AlertsPage)
  43.  
  44. $head = @"
  45. <style>
  46. body { background-color:#dddddd;
  47.        font-family:Tahoma;
  48.        font-size:10pt; }
  49. td, th { border:1px solid black;
  50.          border-collapse:collapse; }
  51. th { color:white;
  52.      background-color:black; }
  53. table, tr, td, th { padding: 2px; margin: 0px }
  54. table {width:100% margin-left:0px; }
  55. </style>
  56.  
  57. "@
  58.  
  59. $webBrowser1 = new-object system.net.webclient
  60. $rssFeed = [xml]$webBrowser1.DownloadString('https://*/jf36ohodxnw7oemghsau1t7qb0w4y708.rss')
  61. $items = $rssFeed.rss.channel.item |
  62.    ForEach-Object {
  63.        [PSCustomObject]@{
  64.            Date = [datetime]$_.pubDate
  65.            Title = $_.title
  66.             Description = [string]$_.description.innertext -replace '<br ?/?>',[System.Environment]::NewLine -replace '<[^>]+>'
  67.            #Category = [string]$_.description.innertext -replace '<br ?/?>',[System.Environment]::NewLine -replace '<[^>]+>'
  68.        }
  69. }
  70. $items |Sort-Object Date -Descending | ConvertTo-Html -Head $head | out-File -filepath "c:\Alerts\alert.html"
  71. $webBrowser1 = New-Object System.Windows.Forms.WebBrowser
  72. $webBrowser1.Location = New-Object System.Drawing.Size(10,60)
  73. $webBrowser1.Size = New-Object System.Drawing.Size(690,300)
  74. $webBrowser1.URL= "c:\Alerts\alert.html"
  75. $AlertsPage.Controls.Add($webBrowser1)
  76.  
  77. #Save the initial state of the form
  78. #Init the OnLoad event to correct the initial state of the form
  79. #Show the Form
  80. $form1.ShowDialog()| Out-Null
  81. } #End Function
  82. GenerateForm
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked