Hi,
I'd need to paint a row when certain value in a cell.
Cellpainting is working fine, but can't find rowpainting example.
This is my cellpainting example:
if ($datagridview1.Columns[$_.ColumnIndex].Name -eq 'Enabled')
{
if ($_.Value -eq 'yes')
{
$_.CellStyle.BackColor = 'lightgreen'
}
}
Tried with options like $_.PaintCells() but can't make it work.
Please advise.
J
RowPainting example?
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.
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.
Re: RowPainting example?
RowPrePaint occurs once per row. You an only set the cell back color and contents per cell and it must all be done once. The cell paint events will override any changes made in rowprepaint. It is recommended that all cells that need color changes based on another cell be painted in the CellPainting event. For what you are asking this is all you need to do. Using row events will cause you top do all of the creation of each row by hand. It is not used for most normal adjustments to cell contents and format.
Re: RowPainting example?
Note: I got error
- Index operation failed; the array index evaluated to null..Exception.Message at line 16293
I use
if ($datagridviewAll.Columns[$_.ColumnIndex].Name -eq 'MyValue')
{
try
{
if ($($_.Value -ne $null) -or $($_.Value -ne [System.dbnull]::Value) -or $($_.Value -ne 'MyValue'))
{
if ($_.Value -eq 'True')
{
$_.CellStyle.BackColor = 'lightgrey'
}
}
- Index operation failed; the array index evaluated to null..Exception.Message at line 16293
I use
if ($datagridviewAll.Columns[$_.ColumnIndex].Name -eq 'MyValue')
{
try
{
if ($($_.Value -ne $null) -or $($_.Value -ne [System.dbnull]::Value) -or $($_.Value -ne 'MyValue'))
{
if ($_.Value -eq 'True')
{
$_.CellStyle.BackColor = 'lightgrey'
}
}