Skip to content

DataGrid

Iuga Alexandru edited this page Sep 2, 2018 · 6 revisions

Description

  • Displays tabular data on columns and rows.

Features

  • Optional title - The title row can be displayed or not. If the title is null, the title row is hidden.
  • Title horizontal alignment - The title text can be aligned to left, center or right, inside the title row.
  • Optional column headers
  • Optional border
  • Custom border template - Three types of borders are provided out-of-the-box:
    • plus-minus (+---+)
    • single-line (┌───┐)
    • double-line (╔═══╗)
  • Data cell horizontal alignment - At cell, row, column, table level.
  • Header cell horizontal alignment - At cell, column, table level.
  • Generate from DataTable or a List - Using reflection.

Obs: when content is aligned to center and there is an odd number of spaces, the content is aligned slightly to the left.

Example

DataGrid dataGrid = new DataGrid("Double-line Border");

dataGrid.Columns.Add("One");
dataGrid.Columns.Add("Two");
dataGrid.Columns.Add("Three");
dataGrid.Columns.Add("Four");

dataGrid.AddRow("1,1", "1,2", "1,3", "1,4");
dataGrid.AddRow("2,1", "2,2", "2,3", "2,4");
dataGrid.AddRow("3,1", "3,2", "3,3", "3,4");
dataGrid.AddRow("4,1", "4,2", "4,3", "4,4");

dataGrid.DrawLinesBetweenRows = true;
dataGrid.DisplayColumnHeaders = true;

dataGrid.Border = BorderTemplate.DoubleLineBorderTemplate;

dataGrid.Display();

Result:

Clone this wiki locally