RowPainting example?

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.
Post Reply
User avatar
Posts: 419
Joined: Wed Jun 15, 2016 2:26 am

RowPainting example?

Post by stevens »


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.

Posts: 14573
Joined: Tue May 22, 2007 9:57 am
Answers: 1
Been upvoted: 1 time

Re: RowPainting example?

Post by jvierra »

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.

Post Reply