Skip to main content

DataGridView Visual Columns

Wisej.NET 4.2.0+

A support queue grid with a subtitle, avatar, chip, meter, sparkline, and actions column.

Wisej.NET 4.2 adds six column types to the DataGridView that draw a small visual in each cell instead of plain text: a two-line label, a portrait with a name, a status chip, a capacity bar, a trend line, and a row of action buttons. They turn a grid of records into the kind of list modern business applications show (a ticket queue, a list of servers, a sales pipeline) without templates, custom cell renderers, or HTML in your data.

The columns are drop-in DataGridViewColumn types: add them to Columns in the designer or in code, bind them with DataPropertyName, and the grid keeps its selection, styles, sorting, and virtualization. The cell's Value stays the bound application value; only what is sent to the browser is a presentation of it. All six are read-only and have no editor.

info

For a complete list of properties, methods, and events, see the DataGridView API documentation and the page of each column linked below.

Features​

Shared Behavior​

Every column has a matching cell type (DataGridViewChipCell for DataGridViewChipColumn, and so on) derived from DataGridViewVisualCell. Properties ending in Member (SubtitleMember, ImageMember, ToneMember, MaximumMember, and the others) name a second value for the same row: the path is resolved against the row's DataBoundItem first, then against the unbound columns of the grid by name. Changing a column property refreshes the grid.

Clicking anywhere in a cell still raises the grid's CellClick. The interactive columns also raise their own events (AvatarClick, ChipClick, ChipClosed, ActionClick) with a DataGridViewVisualCellEventArgs, which adds the row's DataBoundItem, the cell Value, and, for actions, the Action that was clicked to the usual ColumnIndex and RowIndex. A focused cell can be activated with Enter or Space.

DataGridViewSubtitleColumn​

API

Shows the cell value on the first line and the value of SubtitleMember below it, in a smaller, muted font: a customer name and its account number, a ticket title and its reporter. SubtitleFont overrides the font of the second line, and Monospace uses a monospace face for the first, for ids and codes.

DataGridViewAvatarColumn​

API

Shows a portrait followed by a name and an optional second line. The name is the cell value, or the value of TextMember; the second line comes from SubTextMember; the portrait from ImageMember, which can name an Image or an image URL. Without an image, the portrait shows the initials on a colour derived from the name when AutoColor is true (the default). Size sets the diameter (12 to 128 pixels, default 32) and Shape is Circle, Rounded, or Square. Clicking the portrait raises AvatarClick.

DataGridViewChipColumn​

API

Shows the cell value as a coloured chip, for statuses, priorities, and categories. The colour is a ChipTone (Neutral, Primary, Success, Warning, or Danger) taken from ToneMember when it names a valid tone, otherwise from ToneMap, a case-insensitive dictionary from the value text to a tone; unmapped values are Neutral. Variant is Soft (the default), Filled, or Outline, and ShowDot adds a status dot before the text. With Closable set to true, the chip has a close button that raises ChipClosed without changing the bound value; clicking the chip raises ChipClick.

DataGridViewMeterColumn​

API

Shows the numeric cell value as a capacity bar: disk usage, budget spent, stock level. The bar is full at Maximum (default 100), or at the value of MaximumMember when each row has its own capacity. Thresholds holds MeterThreshold entries that switch the bar colour as the value crosses absolute boundaries, the same way they do on the MeterBar control. With ShowText (default true), the value is written below the bar as "value / maximum", or as the value of TextMember. BarHeight sets the thickness of the bar (default 5 pixels).

DataGridViewSparklineColumn​

API

Shows a compact trend chart. The cell value is a double[] of samples; ChartType draws it as a Line (the default), an Area, or Bars, in the colour of Tone or of the per-row ToneMember. Minimum and Maximum fix the vertical range, which otherwise follows the samples, so rows can be compared on the same scale. ShowValue writes the latest sample beside the chart, formatted with ValueFormat (default {0:N0}).

For values that are not already arrays, set Series to a ChartSeries: it projects an enumerable cell value through its ValueMember, or supplies its own data.

DataGridViewActionsColumn​

API

Shows a row of buttons, the same in every row, for commands on the record: open, assign, archive. The buttons are the CardAction objects in Actions, each with a Text, an Icon, a Name you use to tell them apart, and the Primary and Enabled flags. Overflow (default 3) is the number of buttons shown before the rest move to a "More actions" menu; 0 shows them all. IconOnly (default true) hides the text of buttons that have an icon, keeping it as a tooltip, and ShowOnHover reveals the buttons only on the hovered or focused row. Clicking a button raises ActionClick with the CardAction in e.Action. A disabled or removed action cannot be executed.

How To​

Build a Support Queue​

var ticket = new DataGridViewSubtitleColumn { DataPropertyName = "Title", SubtitleMember = "Number", HeaderText = "Ticket" };
var agent = new DataGridViewAvatarColumn { DataPropertyName = "AgentName", SubTextMember = "Team", ImageMember = "AgentPhotoUrl", HeaderText = "Assignee" };
var status = new DataGridViewChipColumn { DataPropertyName = "Status", ShowDot = true, HeaderText = "Status" };
status.ToneMap["Open"] = ChipTone.Primary;
status.ToneMap["Waiting"] = ChipTone.Warning;
status.ToneMap["Escalated"] = ChipTone.Danger;
status.ToneMap["Resolved"] = ChipTone.Success;

var sla = new DataGridViewMeterColumn { DataPropertyName = "HoursOpen", Maximum = 48, TextMember = "SlaText", HeaderText = "SLA" };
sla.Thresholds.Add(new MeterThreshold(24, MeterTone.Warning));
sla.Thresholds.Add(new MeterThreshold(40, MeterTone.Danger));

var replies = new DataGridViewSparklineColumn { DataPropertyName = "RepliesPerDay", ChartType = SparklineChartType.Bar, ShowValue = true, HeaderText = "Replies" };

this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.Columns.AddRange(ticket, agent, status, sla, replies);
this.dataGridView1.DataSource = ticketService.GetOpenTickets(); // RepliesPerDay is a double[].

Add Row Actions​

var actions = new DataGridViewActionsColumn { HeaderText = "", Overflow = 2, ShowOnHover = true };
actions.Actions.Add(new CardAction { Name = "open", Text = "Open", Icon = "icon-preview", Primary = true });
actions.Actions.Add(new CardAction { Name = "assign", Text = "Assign to me", Icon = "Images/assign.svg" });
actions.Actions.Add(new CardAction { Name = "close", Text = "Close ticket", Icon = "icon-close" });
actions.ActionClick += Actions_ActionClick;
this.dataGridView1.Columns.Add(actions);

private void Actions_ActionClick(object sender, DataGridViewVisualCellEventArgs e)
{
var ticket = (Ticket)e.DataBoundItem;
switch (e.Action.Name)
{
case "open": new TicketForm(ticket).Show(); break;
case "assign": ticketService.Assign(ticket.Id, currentUser.Id); break;
case "close": ticketService.Close(ticket.Id); break;
}
}

React to Chip and Avatar Clicks​

status.Closable = true;
status.ChipClick += (s, e) => this.filterStatus.Text = Convert.ToString(e.Value);
status.ChipClosed += (s, e) =>
{
// The bound value does not change; update the record yourself.
var ticket = (Ticket)e.DataBoundItem;
ticketService.ClearStatus(ticket.Id);
};

agent.AvatarClick += (s, e) => AlertBox.Show($"{((Ticket)e.DataBoundItem).AgentName} is on the {((Ticket)e.DataBoundItem).Team} team.");

Advanced​

JavaScript Widget​

ItemDescription
Class name"wisej.web.datagrid.cellRenderer.NewControlsCell", the cell renderer shared by all six column types (CellRenderer of DataGridViewVisualCell). It draws each cell as lightweight HTML inside the grid's own cell, so the columns keep the grid's virtualization.
Theme appearance"newcontrols-grid", with the components "row", "stack", "detail", "avatar", "chip", "chip-button", "track", "fill", "action", "actions" and "sparkline-value"; tones and variants are states of those components. See Themes.