DataGridView Mastery
This example is the DataGridView section is the Orders grid —
ordersGrid+ anordersSourceBindingSource,AutoGenerateColumns = falseand six explicit columns;- a status cell with
AllowHtmlwhose badge is built inordersGrid_CellFormattingwithWebUtility.HtmlEncode; - a custom editor (
MonthCalendaroncolDueDate.Editor, moved byCellBeginEdit/CellEndEdit) and a command column (colOpen) that callsOrderService.GetOrder(id); - a virtual-mode path:
RowCountfrom the service,CellValueNeededserved byOrderCache, pages prefetched inDataRead; - a filter strip docked Top and a status strip docked Bottom, layered with
SendToBack/BringToFront.
This module fills Sections/DataGridViewPage and adds Orders/, two models, two services and docs/GridDecisions.md.
Run it
cd "LearnWisej-Samples/Mastering the Control Library Course/Module 5/OperationsConsole"
dotnet run -f net10.0 --urls http://localhost:5705
Then open http://localhost:5705 and select DataGridView.
What to try
| Action | What you should see |
|---|---|
| Open DataGridView | the first 250 of 4,000 orders with status badges; amber status suggests narrowing the filter or Virtual mode |
Type Contoso, Apply | the loader for a moment, then the matching orders and a green status |
| Pick a status, Apply | the same, filtered |
Type zzzz, Apply | the grid's "No orders match this filter." card, amber status |
| Click a row | status strip Selected: SO-100123, StatusBar Record: SO-100123 |
| Click Open in a row | an info Toast and the whole order on the status line |
| Double-click a due date, pick a later day, leave the cell | green status and Toast; the cell shows the new date |
| …pick a day in the past | red status "A due date in the past cannot be saved …"; the cell keeps the stored date |
| Tick Virtual mode | Rows: 4,000; scroll and the page-fetch count grows by one per 200-row block |
| Tick Simulate service failure, Apply | red status and an error Toast; the rows on screen stay. Untick and Apply again to recover |
| Refresh on the ToolBar | re-runs the current filter on the current path |
Where things live
OperationsConsole/
├─ Sections/DataGridViewPage.cs / .Designer.cs grid, strips, cell handlers
├─ Orders/OrderFilter.cs, OrderColumns.cs, OrderUpdateResult.cs
├─ Models/OrderRow.cs, OrderPage.cs
├─ Services/OrderService.cs 4,000 generated orders, GetOrders / Count / GetPage / GetOrder / UpdateDueDate, SimulateFailure
├─ Services/OrderCache.cs the page cache behind CellValueNeeded (200-row pages, 4 pages, never throws)
└─ docs/GridDecisions.md column, editor, large-data and composition decisions
Known simplifications
- 4,000 generated orders instead of the 200,000 — enough to show page fetches and eviction.
- The bound path is capped at 250 rows on purpose.
- The due-date column is read-only on the virtual path (the cache is a read model).
- Wisej.NET 4.1 has no
CellContentClick; the command column is wired toCellClickand keeps the handler name.