DataGridView Cell Painting
The operations grid arrives: 1,000
generated MachineStatus rows, with UserPaint on the Health and Trend columns only and one guarded
CellPaint handler behind both. A third column renders the same severity through AllowHtml, so the
two approaches can be compared on the same scroll.
The three remaining Module 1 surfaces - Label + ProgressBar, a Wisej.Web.Canvas and an
off-screen Bitmap in a PictureBox - stay on the operations page under the gauges, so the same
reading can still be compared across surfaces. Surface 2, the inline Paint handler, is now the
TelemetryGauge control itself.
This folder is the complete application at this point in the course, with its own solution and port.
Run it
cd "Drawing and Painting Course/Module 3/VisualOperationsStudio"
dotnet run -f net10.0 --urls http://localhost:6003
Open http://localhost:6003. In Visual Studio, open VisualOperationsStudio.slnx and press F5.
Painted surfaces fill in over the first seconds — the gauges last, because they are the largest images.
What to try
| Action | Expected result |
|---|---|
Look at a healthy row (Press 001, 82 %) | A full green bar with its number, and a nearly flat sparkline. |
Look at a row past the warning threshold (Press 004, 40 %) | The bar switches to amber and keeps its number readable. Below 35 % it turns red. |
| Find a row whose Trend cell is empty (every twelfth row has one reading) | Nothing is drawn — fewer than two points is not a line — and nothing throws. |
| Drag the scrollbar from top to bottom | Every newly visible cell calls the handler again. That is why there is no lookup, allocation or file access in it. |
| Click a row | Both painted cells redraw with the selected row's colours. |
| Compare the two status columns | Status (AllowHtml) says the same thing in words a screen reader can read. Lab3Notes.md records which one this sample would ship. |
Comment out this.colHealth.UserPaint = true; | CellPaint stops firing for Health; the cell falls back to ordinary content; Trend keeps painting. |
| Press Take reading | The gauges from Module 2 still behave: one value moves, one repaint. |