Re: Converting from HTML output to GridView
Posted: Tue Jan 13, 2015 11:21 am
You are using V2 setting. PsCustomObject will not work with V2. Switch to V3 or V4.
SAPIEN Technologies Inc.
https://www.sapien.com/forums/
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
}
}
}
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
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.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?
.
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.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.