# MgGrid — Master-Detail > Part of the MgGrid system. See `README.md` for overview and component hierarchy. ## How It Works 1. `MgGridBase.BuildRenderTree` wraps content in `CascadingValue` 2. Child grids receive this via `[CascadingParameter] IMgGridBase? ParentGrid` 3. `IsMasterGrid` = `ParentDataItem == null` 4. `GetRootGrid()` walks the `ParentGrid` chain to find the topmost grid ## Detail Grid Setup ```razor @{ var parent = (ParentEntity)context.DataItem; } ``` When `ParentDataItem` is set and `KeyFieldNameToParentId` is provided, new items automatically get their parent FK set via reflection.