What is the DevExpress XtraGrid and how are its Views and Levels structured?

DevExpress Data Grid Intermediate 1–2 Yrs2–3 Yrs3–5 Yrs Conceptual 1 min read

Quick Answer

In WinForms, GridControl is the data-bound container and a View (usually GridView) is how the data is presented — columns, grouping, sorting, summaries. One GridControl can host multiple views arranged in levels for master-detail: the top-level view shows master rows, and each detail relationship gets its own view at the next level.

The GridControl is the container you bind the data source to, and the GridView is the actual presentation — the columns, grouping, sorting and summaries all live on the view. For master-detail you use levels: the GridControl can hold several views, with the master view at the top level and a pattern view for each detail relationship at the level below. Columns are usually bound to a field by FieldName, but you can also have unbound columns that you populate from an expression or the CustomUnboundColumnData event. The events I use most are CustomColumnDisplayText for formatting, RowCellStyle for conditional colours, and FocusedRowChanged.

  • GridControl — set DataSource here. It renders whichever view is active.
  • GridView (or BandedGridView, CardView, LayoutView) — the presentation. Columns live on the view; you can auto-populate them from the data source or define them explicitly.
  • Levels — for master-detail, the data source exposes a relationship (e.g. a DataSet relation or a collection property). Each detail level has a pattern view that formats those rows.
  • Bound columns map to a field via FieldName; unbound columns have no field and are filled with UnboundExpression or the CustomUnboundColumnData event.

Key events: CustomColumnDisplayText (formatting), RowCellStyle (conditional styling), FocusedRowChanged, CellValueChanged. Grid state (layout, filters) can be saved/restored with SaveLayoutToXml / RestoreLayoutFromXml.