vcl-157003-expresspivotgrid-concepts-how-to-display-underlying-records.md
The following example shows how to display the records from the control’s underlying data source which correspond to a particular cell. A new form with our ExpressQuantumGrid control that displays these records in an unbound TableView is opened when a particular cell in the ExpressPivotGrid control is double-clicked. Note that the ExpressQuantumGrid is a separate product.
The following image shows a sample ExpressPivotGrid control which is bound to the Orders table that is shipped with the control’s demos.
Double-clicking the fourth cell in the January 2002 column will invoke the form with the grid which lists all the payments made in January 2002 by Visa cards.
uses
... cxCustomData, cxGridTableView, ...
// This form contains the ExpressQuantumGrid with an unbound TableView.
TForm2 = class(TForm)
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
cxGrid1TableView1: TcxGridTableView;
end;
// Creates a drilldown data source for a particular cross cell and displays its data in a form.
procedure cxShowDrillDownDataSource(ACrossCell: TcxPivotGridCrossCell);
// Creates columns in the grid's TableView for all the pivot grid fields.
procedure CreateColumns(APivotGrid: TcxCustomPivotGrid; AGridView: TcxGridTableView);
var
I: Integer;
AField: TcxPivotGridField;
begin
for I := 0 to APivotGrid.FieldCount - 1 do
begin
AField := APivotGrid.Fields[I];
with AGridView.CreateColumn do
begin
Caption := AField.Caption;
Visible := AField.Visible;
Hidden := AField.Hidden;
end;
end;
end;
var
AForm: TForm2;
ADataSource: TcxCustomDataSource;
begin
AForm := TForm2.Create(nil);
try
CreateColumns(ACrossCell.PivotGrid, AForm.cxGrid1TableView1);
ADataSource := ACrossCell.CreateDrillDownDataSource;
try
// Links a drilldown data source to the grid's TableView.
AForm.cxGrid1TableView1.DataController.CustomDataSource := ADataSource;
AForm.ShowModal;
finally
ADataSource.Free;
end;
finally
AForm.Free;
end;
end;
// The pivot grid's OnDblClick event handler.
procedure TForm1.cxDBPivotGrid1DblClick(Sender: TObject);
var
ACrossCell: TcxPivotGridCrossCell;
begin
with cxDBPivotGrid1.HitTest do
begin
// Handles double-clicks on data cells
if HitAtDataCell then
begin
// Determines a cross cell which corresponds to the data cell being clicked.
ACrossCell := TcxPivotGridDataCellViewInfo(HitObject).CrossCell;
cxShowDrillDownDataSource(ACrossCell);
end;
end;
end;
//unit2.h
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TcxGridLevel *cxGrid1Level1;
TcxGrid *cxGrid1;
TcxGridTableView *cxGrid1TableView1;
private: // User declarations
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
// Creates a drilldown data source for a particular cross cell and displays its data in a form.
void cxShowDrillDownDataSource(TcxPivotGridCrossCell *ACrossCell);
//unit2.cpp
// Creates a drilldown data source for a particular cross cell and displays its data in a form.
void cxShowDrillDownDataSource(TcxPivotGridCrossCell *ACrossCell)
{
TForm2 *AForm = new TForm2(NULL);
try {
// Creates columns in the grid's TableView for all the pivot grid fields.
for(int I = 0; I < ACrossCell->PivotGrid->FieldCount; I++) {
TcxPivotGridField *AField = ACrossCell->PivotGrid->Fields[I];
TcxGridColumn *AColumn = AForm->cxGrid1TableView1->CreateColumn();
AColumn->Caption = AField->Caption;
AColumn->Visible = AField->Visible;
AColumn->Hidden = AField->Hidden;
}
TcxCustomDataSource *ADataSource = ACrossCell->CreateDrillDownDataSource();
try {
// Links a drilldown data source to the grid's TableView.
AForm->cxGrid1TableView1->DataController->CustomDataSource = ADataSource;
AForm->ShowModal();
}
__finally {
delete ADataSource;
}
}
__finally {
delete AForm;
}
}
// unit1.cpp
void __fastcall <TForm>::DBPivotGridDblClick(TObject *Sender)
{
// Handles double-clicks on data cells
if(cxDBPivotGrid1->HitTest->HitAtDataCell) {
// Determines a cross cell which corresponds to the data cell being clicked.
TcxPivotGridCrossCell *ACrossCell =
((TcxPivotGridDataCellViewInfo*)cxDBPivotGrid1->HitTest->HitObject)->CrossCell;
cxShowDrillDownDataSource(ACrossCell);
}
}