Skip to main content

Process Master Rows

  • 3 minutes to read

Each data record in a master Table View is represented by a TcxGridMasterDataRow object. Most operations (getting cell values, selecting, focusing, expanding) for master rows can be performed in the same manner as for other row types. However, some operations are specific to master rows:

  • getting the detail View for the given row.

The following code shows how to get the detail View corresponding to the focused master row within the currently focused master grid View. The Expand method is used to create the detail View if it does not exist yet. After the detail View has been created, it can be accessed via the ActiveDetailGridView property.

var
  ARecord: TcxCustomGridRecord;
  ADetailView: TcxCustomGridView;
//...
  ADetailView := nil;
  ARecord := TcxGridTableView(Grid.FocusedView).Controller.FocusedRecord;
  if ARecord is TcxGridMasterDataRow then
    with TcxGridMasterDataRow(ARecord) do
    begin
      Expand(False);
      ADetailView := ActiveDetailGridView;
    end;
  • switching between detail Views for a specific master row

One master View can be associated with one or more detail Views displayed at the same hierarchy level. The next image shows the tvFilms View bound to three detail Views (cvPeople, tvCompanies and cvPhotos).

The current active detail opened for a specific master row is determined by the ActiveDetailGridView property. To switch between different sibling details programmatically, use the ActiveDetailIndex property.

The ToggleActiveDetail procedure allows you to switch between details for the focused master row within the currently focused master grid View. When the tvFilms View is focused, this toggles between cvPeople, tvCompanies and cvPhotos details.

ToggleActiveDetail works even when the tab panel for switching between details is not visible (when the master level’s Options.DetailTabsPosition is set to dtpNone).

The helper NextVisibleLevelIndex routine is used to get the index of the next visible sibling level for the given TcxGridLevel object.

procedure TForm1.ToggleActiveDetail;
  function NextVisibleLevelIndex(ADetailLevel: TcxGridLevel): Integer;
  begin
    Result := 0;
    with ADetailLevel do
    begin
      if (Parent.VisibleCount > 1) and 
        (VisibleIndex < Parent.VisibleCount - 1) then
        Result := Parent.VisibleItems[VisibleIndex + 1].Index;
    end;
  end;
var
  AView: TcxCustomGridTableView;
  ARecord: TcxCustomGridRecord;
begin
  AView := TcxCustomGridTableView(Grid.FocusedView);
  ARecord := AView.Controller.FocusedRecord;
  if ARecord is TcxGridMasterDataRow then
    with TcxGridMasterDataRow(ARecord) do
    begin
      Expand(False);
      ActiveDetailIndex := NextVisibleLevelIndex(ActiveDetailLevel);
    end;
end;