EmptyState
Wisej.NET 4.2.0+
An EmptyState fills the space a view leaves when it has nothing to show: an illustration, a heading, a sentence of explanation, and up to two buttons that tell the user what to do next. "No orders yet — Create order", "No results found — Clear filters", "You are offline — Retry".
It is a placeholder rather than a message box: it sits where the data would be, and it raises events instead of doing anything itself. Placed on its own it is a panel like any other. Pointed at a DataGridView or a ListView through TargetControl, it lays itself over that control whenever the control has no rows and gets out of the way as soon as it has some.
For a complete list of properties, methods, and events, see the API documentation.
Features
Kinds and Default Text
Kind selects the illustration and the built-in, localized text for four common situations:
| Kind | Default heading | Default explanation |
|---|---|---|
Empty | Nothing here yet | New items will appear here. |
NoResults | No results found | Try changing your search or filters. |
Error | Something went wrong | The content could not be loaded. |
Offline | You are offline | Check your connection and try again. |
Title and Description override them. Left at null they use the localized default for the kind; set to an empty string they hide the line altogether.
Actions
ActionText shows a primary button and SecondaryActionText a secondary one; either is hidden while its text is empty. They raise ActionClick and SecondaryActionClick. Neither changes the displayed state — the empty state stays until the data arrives or your code hides it.
Illustration
The kind's built-in illustration is a simple line drawing in the theme's colours. Icon replaces it with an image URL or a theme image name, and Image with an Image instance, which takes precedence over both. Images remain owned by your code.
Layout
By default the illustration, text and buttons are stacked and centred. Compact lays them out in a row, which suits a narrow strip such as the body of a dashboard tile or a short list. Bordered draws the theme's dashed outline around the control, the usual look for a drop target or an area that is waiting to be filled.
Overlaying a Grid or List
TargetControl accepts an existing DataGridView or ListView. The empty state becomes a sibling of that control, follows its bounds and visibility, and shows itself only while the control has no data — reacting to row and item changes and to data binding on its own. A grid's new-row placeholder does not count as data. The target itself is never hidden or disposed; clear TargetControl to use the empty state on its own again.
A target in virtual mode changes its row count without raising collection events: call RefreshTarget() after changing VirtualListSize. Do not use a target inside a layout-managed container such as a FlowLayoutPanel, where the overlay cannot sit on top of it.
How To
Cover an Empty Grid
Point the empty state at the grid. It appears while the grid is empty and disappears when rows are added or bound.
var empty = new EmptyState
{
TargetControl = this.ordersGrid,
Title = "No orders yet",
Description = "Orders placed by your customers will be listed here.",
ActionText = "Create order",
SecondaryActionText = "Import from CSV"
};
empty.ActionClick += (s, e) => new OrderEditor().ShowDialog();
empty.SecondaryActionClick += (s, e) => ImportOrders();
this.ordersGrid.DataSource = orderService.GetOrders(customerId);
Explain a Search with No Matches
Switch the kind to match the situation; the default text follows.
void ApplySearch(string query)
{
var results = ticketService.Search(query);
this.ticketsGrid.DataSource = results;
this.ticketsEmpty.Kind = EmptyStateKind.NoResults;
this.ticketsEmpty.Title = $"No tickets match \"{query}\"";
this.ticketsEmpty.Description = null; // Localized default for NoResults.
this.ticketsEmpty.ActionText = "Clear search";
}
Show a Load Error
Use the Error kind with a retry action when the data could not be loaded at all.
try
{
this.shipmentsGrid.DataSource = shipmentService.GetPending();
}
catch (TimeoutException)
{
this.shipmentsEmpty.Kind = EmptyStateKind.Error;
this.shipmentsEmpty.ActionText = "Try again";
this.shipmentsEmpty.Visible = true;
}
Advanced
JavaScript Widget
| Item | Description |
|---|---|
| Class name | "wisej.web.EmptyState" |
| Theme appearance | "emptystate", see Themes. States: "bordered", "compact", "error", "offline". |
| Child components | "body" holds "art", "text" and "actions". "art" shows the built-in "symbol" or the "image". "text" holds "title" and "description". "actions" holds the "action" and "secondary" buttons. See JavaScript. |