Master-detail

GridControl

Two grids, one selection: pick a row in the first and the second shows what belongs to it.

Overview

A master-detail screen is two ordinary grids and one event. The master grid raises RowSelected (a GridControlEvents callback passed through EventsRef) with the selected row in args.Data; the page filters its detail list by that row's key and binds the result to the second grid's DataSource. SelectionSettings with SelectionType.Single keeps one master row selected, and AutoSelectFirstRow selects the first row as soon as the grid has rows and raises RowSelected for it, so the detail fills on arrival. RowSelecting can refuse a move while the detail has unsaved edits; the Unsaved-row lock page shows that.

Examples

#Security groups and their members

Seven groups on the left, 126 users on the right. Click a group and the right grid shows its members; the Users column of the group row, the member grid's footer and the line under the grids count the same people. The member grid sorts on its own and marks inactive accounts.

Example
Razor
C#

Groups

Group Admin Users
Executive ManagementTrue6
Project ManagersFalse24
Estimating SpecialistsFalse12
Purchasing & SubcontractsFalse18
Accounting & PayrollFalse15
Field SuperintendentsFalse42
Customer Care & WarrantyFalse9

Members of Executive Management

Login Name Email Active
asmithAlex Smithasmith@enterprise.localTrue
bharrisBradley Harrisbharris@enterprise.localTrue
cortizCatherine Ortizcortiz@enterprise.localTrue
dvargasDavid Vargasdvargas@enterprise.localTrue
eclarkElena Clarkeclark@enterprise.localFalse
fjonesFrank Jonesfjones@enterprise.localTrue
6 rows

6 members of Executive Management, 1 inactive.

Documentation

GridControl selection parameters

ParameterTypeDefaultDescription
AllowSelectionbooltrueFalse makes the grid cursor-only: clicks and keys still move the active cell, editing and the click events still work, but nothing is ever selected and no selection event fires.
AutoSelectFirstRowboolfalseSelects the first visible row when a selectable grid first receives rows, and again after a sort changes the order. Raises RowSelected but not RowSelecting. Skipped in Cell mode and with CheckboxOnly.
InitialSelectedRowIndexint?nullDisplayed-row index to select before the first paint, for pickers that already know their value. Applied again when the data source or the index changes.
HighlightSelectedRowsbooltrueFalse keeps the selection and its events but does not paint the selected rows.
SelectionSettingsRefSelectionSettings?nullThe settings object below. Null behaves as single row selection.
EventsRefGridControlEvents<TValue>?nullThe object that holds the callbacks; the grid has no separate parameters for the selection events.

SelectionSettings

PropertyTypeDefaultDescription
TypeSelectionTypeSelectionType.SingleSingle keeps one row; Ctrl or Shift with a click or an arrow still extends it unless ModifierKeysExtendSelection is off. Multiple: a plain click still collapses to the clicked row; Ctrl toggles a row, Shift selects the visible range from the last selected row.
ModeSelectionModeSelectionMode.RowRow or Cell. In Cell mode the selected set is cells, SelectionChanged counts cells, and AutoSelectFirstRow is skipped.
ShowCheckboxesboolfalseAdds the selection checkbox column while ordinary clicks still select.
CheckboxOnlyboolfalseOnly the checkboxes change the selection; a click on a cell does not, and AutoSelectFirstRow is skipped.
ModifierKeysExtendSelectionbooltrueWith Single, Ctrl or Shift plus a click or Shift plus an arrow add rows. False keeps exactly one row: a modifier click selects the clicked row alone. Ignored for Multiple and for Cell mode.
MultiSelectBehaviorGridMultiSelectBehaviorGridMultiSelectBehavior.FullMultiSelectWith BatchEditBehavior = MultiRow and several rows selected, FullMultiSelect keeps the selection when a plain click lands on an editable, template or command cell inside it, so a bulk edit stays armed; VBMultiSelect lets that click collapse to the clicked row. Ctrl, Shift and drag build multi-row selections in both.
EnableTogglebooltrueDeclared, but GridControl never reads it.
PersistSelectionboolfalseDeclared, but GridControl never reads it.

GridControlEvents, selection

EventPayloadDescription
RowSelectingRowSelectEventArgs<TValue>Before a row is selected by mouse, keyboard or checkbox toggle. Set Cancel to refuse. Not raised by AutoSelectFirstRow, type-ahead moves or the selection methods.
RowSelectedRowSelectEventArgs<TValue>After a row is selected by mouse, keyboard, checkbox toggle, type-ahead search or AutoSelectFirstRow. Not raised during drag-select or by the selection methods.
SelectionChangedintAfter any change to the selected set: click, drag-select, Select All, Clear, the selection methods. The payload is the selected count, rows or cells by Mode.
SelectionChangedDetailedGridSelectionChangedArgsSame timing, with Count and Source: Pointer, MouseDrag, Keyboard, Programmatic or Unknown.
RowDeselecting / RowDeselectedRowSelectEventArgs<TValue>Declared, but GridControl never raises them. TreeGridControl raises RowDeselected.

RowSelectEventArgs<TValue>

PropertyTypeDefaultDescription
DataTValue?nullThe row.
RowIndexint0The row's index in the grid's current display order.
CancelboolfalseSet in RowSelecting to keep the current selection. Ignored by RowSelected.

Selection methods

MethodInputsReturnsDescription
GetSelectedRecords()—IEnumerable<TValue>The selected rows, in selection order.
GetSelectedRecordsAsync()—Task<List<TValue>>The same as a list.
SelectRow()int rowIndexvoidSelects the displayed row at that index; with Single it replaces the selection, otherwise it adds.
SelectRowIndexAsync()int rowIndexTaskSelectRow as a task.
SelectAndRevealRowAsync()TValue item
bool clearExistingSelection = false
TaskSelects the row and scrolls it into view when it is off-screen, in one paint.
ClearSelection()—voidClears rows and cells.
ClearSelectionAsync()—TaskClearSelection as a task.

GridControlEvents also carries the sorting, filtering, paging, editing, grouping, resizing, reordering and cell events; those belong with the pages that use them. The methods above change the selection without raising RowSelecting or RowSelected; they raise SelectionChanged with the source Programmatic.

An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.