Back to Devexpress

LookUpHelper Class

corelibraries-devexpress-dot-xtrareports-dot-parameters-63d8d400.md

latest4.7 KB
Original Source

LookUpHelper Class

Contains methods that allow you to access parameter look-up values.

Namespace : DevExpress.XtraReports.Parameters

Assembly : DevExpress.Printing.v25.2.Core.dll

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public static class LookUpHelper
vb
Public Module LookUpHelper

Remarks

Use the LookUpHelper class to access look-up values for report parameters with predefined static and dynamic values.

If you handle the BeforePrint event to fill the list with parameter values, you do not need to call the Fill method of the data source. When you handle the XtraReport.ParametersRequestBeforeShow event, the parameter data source must be filled with data before you call the LookUpHelper methods. Otherwise, the list of dynamic parameter values will be empty. For more information, review the following help topic: Report Events.

Example

The following code example demonstrates how to use the GetLookUpValues method of the LookUpHelper class to access look-up values of a multi-value report parameter. The example also shows how to display the descriptions of the selected parameter values in the report’s XRLabel control.

csharp
using DevExpress.Data.Browsing;
using DevExpress.XtraReports.Parameters;
using System;
// ...
private void XtraReport1_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
    var valueSourceSettings = this.Parameters["param1"].ValueSourceSettings;
    var dataContext = (sender as IServiceProvider).GetService(typeof(DataContext)) as DataContext;

    var lookupValues = LookUpHelper.GetLookUpValues(valueSourceSettings, dataContext);
    var selectedValues = this.Parameters["param1"].Value as Int32[];

    var text = "";

    int step = 0;
    for (var j = 0; j < lookupValues.Count; j++) {
        if (Array.IndexOf(selectedValues, Convert.ToInt32(lookupValues[j].Value)) > -1) {
            step += 1;
            if (step == selectedValues.Length) {
                text += lookupValues[j].Description;
            } else {
                text += lookupValues[j].Description + ", ";
            }
        }
    }

    xrLabel1.Text = text;
}
vb
Imports DevExpress.Data.Browsing
Imports DevExpress.XtraReports.Parameters
Imports System
' ...
Private Sub XtraReport1_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.BeforePrint
    Dim valueSourceSettings = Me.Parameters("param1").ValueSourceSettings
    Dim dataContext = TryCast((TryCast(sender, IServiceProvider)).GetService(GetType(DataContext)), DataContext)

    Dim lookupValues = LookUpHelper.GetLookUpValues(valueSourceSettings, dataContext)
    Dim selectedValues = TryCast(Me.Parameters("param1").Value, Int32())
    Dim text_Renamed = ""

    Dim [step] As Integer = 0
    For j = 0 To lookupValues.Count - 1
        If Array.IndexOf(selectedValues, Convert.ToInt32(lookupValues(j).Value)) > -1 Then
            [step] += 1
            If [step] = selectedValues.Length Then
                text_Renamed &= lookupValues(j).Description
            Else
                text_Renamed &= lookupValues(j).Description & ", "
            End If
        End If
    Next j

    xrLabel1.Text = text_Renamed
End Sub

Inheritance

Object LookUpHelper

See Also

LookUpHelper Members

DevExpress.XtraReports.Parameters Namespace