Converting from HTML output to GridView

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 9 years and 2 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: Converting from HTML output to GridView

Post by jvierra »

You are using V2 setting. PsCustomObject will not work with V2. Switch to V3 or V4.
User avatar
cstewart28
Posts: 12
Last visit: Thu Sep 01, 2016 8:41 am

Re: Converting from HTML output to GridView

Post by cstewart28 »

I'm trying to change it, but the only option I have from the Platform drop down is V2 - 32 Bit and V2 - 64 Bit.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Converting from HTML output to GridView

Post by jvierra »

Don't you have V3/4 installed? Download and install it from MS.
User avatar
cstewart28
Posts: 12
Last visit: Thu Sep 01, 2016 8:41 am

Re: Converting from HTML output to GridView

Post by cstewart28 »

V4
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Converting from HTML output to GridView

Post by jvierra »

Post in CS forum for PS 2014. There is a fix for that but I do not remember what it is.
User avatar
cstewart28
Posts: 12
Last visit: Thu Sep 01, 2016 8:41 am

Re: Converting from HTML output to GridView

Post by cstewart28 »

I think I have added the progressbar correctly, but now I'm trying to get the rows high lighted based on a value returned from the function and what I found does not seem to work.

Here is the function:

Code: Select all

# utility function to get camera data
function Get-CameraData
{
	Param ($csvfile)
		Import-Csv $csvfile |
		ForEach-Object{
		$progressbaroverlay1.Maximum = $csvfile.count
		$item = $_
		Try
		{
			$timetaken = (Measure-Command { $Request = Invoke-WebRequest -Uri $item.ip }).TotalMilliseconds
			$progressbaroverlay1.PerformStep()
			
		}
		Catch
		{
			$Request = [PsCustomObject]@{
				StatusDescription = $_.Exception.Response
				RawContentLength = 0
				StatusCode = -1
			}
			$timetaken = -1
		}
		[PSCustomObject]@{
			#Time = [datetime]::Now
			Name = $item.name
			Uri = $item.ip
			StatusCode = $Request.StatusCode
			StatusDescription = $Request.StatusDescription
			ResponseLength = $Request.RawContentLength
			TimeTaken = $timetaken
		}
	}
}

here is the Button:

Code: Select all

$buttonCheckCameras_Click = {
	$progressbaroverlay1.TextOverlay = 'Checking Camera...'
	$progressbaroverlay1.Value = 0
	$progressbaroverlay1.Step = 1
	$this.enabled = $false
	$cameradata = Get-CameraData $CSVFileName.Text
	$array = [System.Collections.ArrayList]$cameradata
	#$datagridview.DataSource = [System.Collections.ArrayList]$cameradata
	$dataGridView.ColumnCount = 6
	$dataGridView.ColumnHeadersVisible = $true
	$dataGridView.Columns[0].Name = "Name"
	$dataGridView.Columns[1].Name = "IP Address"
	$dataGridView.Columns[2].Name = "Status Code"
	$dataGridView.Columns[3].Name = "Description"
	$dataGridView.Columns[4].Name = "Web Response Length"
	$dataGridView.Columns[5].Name = "Time Taken(ms)"
	foreach ($item in $array)
	{
		#check if status code is not eqal to 200, which means we can't connect
		#statusCode is 3rd item in attay
		if ($item[2] -ne "200")
		{
			#write data to datagridview
			$datagridview.Rows.Add($_.name,$_.uri,$_.StatusCode,$_.StatusDescription,$_.ResponseLength,$_.TimeTaken)		
			#make the row all red
			$datagridviewResults_CellFormatting = [System.Windows.Forms.DataGridViewCellFormattingEventHandler]{
				$_.CellStyle.BackColor = 'Red'
			}
		}
		
		else
		{
			#write data to datagridview
			$datagridview.Rows.Add($_.name, $_.uri, $_.StatusCode, $_.StatusDescription, $_.ResponseLength, $_.TimeTaken)
			#make the row all green
			$datagridviewResults_CellFormatting = [System.Windows.Forms.DataGridViewCellFormattingEventHandler]{
				$_.CellStyle.BackColor = 'Green'
			}
		}
		
	}
	
	$progressbaroverlay1.Value = $progressbaroverlay1.Maximum
	$progressbaroverlay1.TextOverlay = 'Complete!'
	$this.enabled = $true
Also it takes about 30 seconds to return the data and it seems to be all at one, not per line, any ideas on how I can do that with the individually or does it make more since to do it all at once?

Thanks again this is my first attempt at this.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Converting from HTML output to GridView

Post by jvierra »

Start by loading th gris with all data from the CSV plus extra columns for status. Enumerate the grid and test, update progrss and color.

Your approach is lniear and overly complicated. If you simplify things you will find it is easir to do all of this.

I havebeen designing andbuilding Windows based applicaitons for 20+ years. Believe me it should notbethis hard.

THe grid is anexcellent place to start. It is an array of sorts and is a repository for data. Learn how to load it from an object collection or from a CSV file. Enumerate the grid to perform tasks and mark status.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Converting from HTML output to GridView

Post by jvierra »

cstewart28 wrote: Also it takes about 30 seconds to return the data and it seems to be all at one, not per line, any ideas on how I can do that with the individually or does it make more since to do it all at once?

.
In an event the system is never updated until the event is exited. THe best way to do thisis to use a background job that enumerates the grid and returns incremental results.

Look into the "Job-Tracker" Control Set to help with this.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Converting from HTML output to GridView

Post by jvierra »

cstewart28 wrote:I think I have added the progressbar correctly, but now I'm trying to get the rows high lighted based on a value returned from the function and what I found does not seem to work.
TO update teh format of a row use the row changed event to set teh color or other attirbutes when the row is changed. This allows the form to run in a pure event driven fashion.

Widows and Forms do not work well whenyou use linear programming techniques. Windows is a "state" driven systemm and works best when the state trigegrs and events are used to manage the system/form.
This topic is 9 years and 2 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