Skip to content

DevExpress-Examples/vcl-dashboards-pass-hidden-parameters-to-custom-sql-query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DevExpress Dashboards for Delphi/C++Builder — Pass a Hidden Dashboard Parameter to a SQL Query

This example demonstrates a dashboard that displays sales data for a selected country. The selected country is passed to the underlying SQL query as a hidden dashboard parameter. This sample solution uses the TdxCustomDashboardControl.Parameters property to access and modify the target dashboard parameter.

Prerequisites

DevExpress Reports Prerequisites

Implementation Details

The scenario demonstrated in this project relies on a configured dashboard layout shipped with sample source code.

Follow these steps to add a hidden parameter to a dashboard and use the parameter in a SQL query:

  1. Create a Dashboard Parameter
  2. Create a SQL Query
  3. Bind a Query Parameter to a Dashboard Parameter
  4. Load Parameters From Layout
  5. Assign Parameter Values

Step 1: Create a Dashboard Parameter

  1. Open the DevExpress Dashboard Designer (select the Designer… item from the TdxDashboardControl component's context menu at design time or call the ShowDesigner method in code).

    DevExpress VCL Dashboards — Open the Designer Dialog

  2. Open the dashboard menu and click Parameters.

  3. Create a parameter and configure its settings within the PARAMETERS pane.

  4. Uncheck the Visible check box to hide the parameter in Dashboard Viewer mode.

This sample project creates a hidden parameter named CountryDashboardParameter and sets France as the default value:

DevExpress VCL Dashboards — Add and Configure a Parameter

Step 2: Create a Query

  1. Select Data Sources in the dashboard menu.

  2. Click Add within the DATA SOURCES pane to display the Add Data Source dialog.

  3. Click Create data source… to run the Dashboard Data Source Wizard.

  4. Create a new query as follows:

    DevExpress VCL Dashboards — Use the Query Builder Dialog

Step 3: Bind a Query Parameter to a Dashboard Parameter

  1. Create a new filter within the QUERY PROPERTIES section.

  2. Add a new query parameter named CountryParameter.

  3. Expand the PARAMETERS section.

  4. Switch parameter type to Expression for CountryParameter.

  5. Set the parameter value to CountryDashboardParameter.

    DevExpress VCL Dashboards — Use the Filter Builder Dialog

Step 4: Load Parameters From Layout

The Parameters collection is initially empty. You need to populate the collection at design- or runtime on demand.

Populate Parameters at Runtime

To populate the collection with parameters from a dashboard layout definition, call the Parameters.LoadFromLayout procedure at runtime.

Delphi
dxDashboardControl1.Parameters.LoadFromLayout;
C++
dxDashboardControl1->Parameters->LoadFromLayout();

Populate Parameters at Design Time

Select Load Parameters from Dashboard from the TdxDashboardControl context menu at design time:

DevExpress VCL Dashboards — Load Dashboard Parameters at Design Time

Step 5: Assign Parameter Values

To modify parameters in a dashboard, assign values to individual Parameters collection members as follows:

Delphi
procedure TMainForm.cbCountriesPropertiesEditValueChanged(Sender: TObject);
begin
  dxDashboardControl1.Parameters['CountryDashboardParameter'].Value := cbCountries.EditValue;
end;
C++
void __fastcall TMainForm::cbCountriesPropertiesEditValueChanged(TObject *Sender)
{
  dxDashboardControl1->Parameters->ParamByName[L"CountryDashboardParameter"]->Value =
      cbCountries->EditValue;
}

Documentation

Does This Example Address Your Development Requirements/Objectives?

(you will be redirected to DevExpress.com to submit your response)

About

This example demonstrates a dashboard that displays sales data for a selected country. The selected country is passed to the underlying SQL query as a hidden dashboard parameter.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors