Skip to main content

DataGridView Mastery

This example is the DataGridView section is the Orders grid —

  • ordersGrid + an ordersSource BindingSource, AutoGenerateColumns = false and six explicit columns;
  • a status cell with AllowHtml whose badge is built in ordersGrid_CellFormatting with WebUtility.HtmlEncode;
  • a custom editor (MonthCalendar on colDueDate.Editor, moved by CellBeginEdit / CellEndEdit) and a command column (colOpen) that calls OrderService.GetOrder(id);
  • a virtual-mode path: RowCount from the service, CellValueNeeded served by OrderCache, pages prefetched in DataRead;
  • 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

ActionWhat you should see
Open DataGridViewthe first 250 of 4,000 orders with status badges; amber status suggests narrowing the filter or Virtual mode
Type Contoso, Applythe loader for a moment, then the matching orders and a green status
Pick a status, Applythe same, filtered
Type zzzz, Applythe grid's "No orders match this filter." card, amber status
Click a rowstatus strip Selected: SO-100123, StatusBar Record: SO-100123
Click Open in a rowan info Toast and the whole order on the status line
Double-click a due date, pick a later day, leave the cellgreen status and Toast; the cell shows the new date
…pick a day in the pastred status "A due date in the past cannot be saved …"; the cell keeps the stored date
Tick Virtual modeRows: 4,000; scroll and the page-fetch count grows by one per 200-row block
Tick Simulate service failure, Applyred status and an error Toast; the rows on screen stay. Untick and Apply again to recover
Refresh on the ToolBarre-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 to CellClick and keeps the handler name.