Quantcast
Channel: SAPIEN Forums
Viewing all articles
Browse latest Browse all 546

PowerShell GUIs • Datagridview painting after function Set-ControlTheme

$
0
0
In the function Set-ControlTheme, I added thses vars and then added to the elseif ($target -is [System.Windows.Forms.DataGridView] to paint my dgv

Code:

if ($Theme -eq 'Dark')
{
$global:DGVbackgroundColor = [System.Drawing.Color]::DarkGreen
$global:DGVforegroundColor = [System.Drawing.Color]::White
$global:DGValternateBackgroundColor = $ContainerColor
$global:DGValternateForegroundColor = [System.Drawing.Color]::Gray
}

else
{

$global:DGVbackgroundColor = [System.Drawing.Color]::LightGreen
$global:DGVforegroundColor = [System.Drawing.Color]::Black
$global:DGValternateBackgroundColor = $ContainerColor
$global:DGValternateForegroundColor = [System.Drawing.Color]::Gray
}

elseif ($target -is [System.Windows.Forms.DataGridView])
{

$target.GridColor = [System.Drawing.Color]::Gainsboro
$target.BackgroundColor = $DGValternateBackgroundColor
$target.DefaultCellStyle.BackColor = $DGVbackgroundColor
$target.DefaultCellStyle.ForeColor = $DGVforegroundColor
$target.DefaultCellStyle.SelectionBackColor = $SelectionBackColor
$target.DefaultCellStyle.SelectionForeColor = $SelectionForeColor
$target.ColumnHeadersDefaultCellStyle.BackColor = $DGValternateBackgroundColor
$target.ColumnHeadersDefaultCellStyle.ForeColor = $DGVforegroundColor
$target.EnableHeadersVisualStyles = $false
$target.ColumnHeadersBorderStyle = 'Single'
$target.RowHeadersBorderStyle = 'Single'
$target.RowHeadersDefaultCellStyle.BackColor = $DGValternateBackgroundColor
$target.RowHeadersDefaultCellStyle.ForeColor = $DGVforegroundColor

}
Everything in the form gets updated to the right colors when I invoke the function , even the DGV vars get updated but the dgv does not paint itself to the new colors

if I restart the app, the DGV is painted correctly

I have an event that adds a row to the dgv and I also have this event to paint it after the fact
If I trigger the adding a new row event the DGV gets painted correctly

Code:

$datagridview1_DataBindingComplete = [System.Windows.Forms.DataGridViewBindingCompleteEventHandler]{

foreach ($row in $this.Rows)
{
if (-not $row.IsNewRow)
{
if (-not [string]::IsNullOrEmpty($row.Cells['SomeColumn'].Value))
{
$row.DefaultCellStyle.BackColor = $DGVbackgroundColor
$row.DefaultCellStyle.ForeColor = $DGVforegroundColor
}
else
{
$row.DefaultCellStyle.BackColor = $DGValternateBackgroundColor
$row.DefaultCellStyle.ForeColor = $DGValternateForegroundColor
}

}
}

}
Any help would be appreciated

Statistics: Posted by apowershelluser — Tue Mar 19, 2024 12:29 pm



Viewing all articles
Browse latest Browse all 546

Trending Articles