0

I've been struggling to display either OK.png / NOK.png on a specific column by testing if the path of the actual PV.pdf exists ,

$dataGrid = New-Object System.Windows.Forms.DataGridView
$dataGrid.Width = 503
$dataGrid.Height = 250
$dataGrid.location = new-object system.drawing.point(120,380)
$dataGrid.DataSource = $DataTable
$dataGrid.ReadOnly = $true

$dataGrid.RowHeadersVisible = $false
$dataGrid.AllowUserToAddRows = $false
$dataGrid.AutoSizeColumnsMode = 'Fill'

$ImageColumn = New-Object System.Windows.Forms.DataGridViewImageColumn
$ImageColumn.Width = 40
$dataGrid.Columns.Insert($dataGrid.Columns.Count, $ImageColumn)
$dataGrid.Columns[$dataGrid.Columns.Count - 1].HeaderText = "PV"
$dataGrid.Columns[$dataGrid.Columns.Count - 1].Name = "ImageColumn"


$OKImage = [System.Drawing.Image]::FromFile([string]$curDir+"\images\OK.png")
$NOKImage = [System.Drawing.Image]::FromFile([string]$curDir+"\images\NOK.png")

for($i=0;$i -lt $dataGrid.RowCount;$i++) {
Write-Host $dataGrid.Rows[$i].Cells[1].Value
$dir = [string]$curDir+"\pvs\"+[string]$dataGrid.Rows[$i].Cells[1].Value+".pdf"
if ((Test-Path $dir) -eq $true) {
$dataGrid.Rows[$i].Cells[0].Value = $OKImage
} else {
$dataGrid.Rows[$i].Cells[0].Value = $NOKImage
}
}
$dataGrid.Refresh()

i get this when i run the script : Screenshot

Please help

i was expecting to display the OK.png (20x20) when the file is found and NOK.png when the file is not found .

iRon
  • 20,463
  • 10
  • 53
  • 79
Cinox
  • 1
  • 2
  • try to set your images to iconbase64 and try maybe look to this site https://stackoverflow.com/questions/53376491/how-to-embed-an-icon-in-a-powershell-gui-executable – Kemal K. Feb 08 '23 at 10:12
  • Where did you define `$curDir` ? Also, beter use [Join-Path](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/join-path) when combining strings into a path to make sure you don't forget backslahes or add too many – Theo Feb 08 '23 at 13:11
  • $curDir = Get-Location it gets the local project path , thanks for the new function " Join-Path" i'll use that in future. – Cinox Feb 08 '23 at 15:43

0 Answers0