Skip to main content
A newer version of this page is available. .

IDisplayNameProvider Interface

Provides methods that return custom names for the Field List items.

Namespace: DevExpress.Data

Assembly: DevExpress.Data.v19.1.dll

Declaration

public interface IDisplayNameProvider

The following members return IDisplayNameProvider objects:

Library Related API Members
Cross-Platform Class Library EditQueryContext.DisplayNameProvider
QueryBuilderEditQueryContext.DisplayNameProvider
WinForms Controls EditQueryContext.DisplayNameProvider
QueryBuilderEditQueryContext.DisplayNameProvider

Remarks

Use IDisplayNameProvider to customize your own custom names for the Field List items, using the IDisplayNameProvider.GetDataSourceDisplayName and IDisplayNameProvider.GetFieldDisplayName methods.

For this interface to work correctly, the class which implements the IDisplayNameProvider interface must have a default constructor.

When creating data items, avoid dots in their names, because XtraReports uses them to address data source members.

Example

This example demonstrates how to change the names of items listed in the Field List (both in the Visual Studio Report Designer and End-User Report Designer for WinForms) by making the report’s data source (a DataSet object in this example) implement the IDisplayNameProvider interface.

When a localized field name contains the white space character, leave this white space when referring to this field (e.g. Categories.Categories Products.Discontinued).

When the IDisplayNameProvider.GetFieldDisplayName method returns null or Empty, the corresponding data item becomes hidden in the Field List.

The following image illustrates the look of a Field List before (left picture) and after (right picture) its customization:

IDataDictionary1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.Data;
// ...
class MyDataSet :nwindDataSet, IDisplayNameProvider {
// ...
    string IDisplayNameProvider.GetDataSourceDisplayName() {
        // Substitute the default datasource display name
        // with a custom one.
        return "Northwind Traders";
    }

    string IDisplayNameProvider.GetFieldDisplayName(string[] fieldAccessors) {
        // Get a field name form the data member's name. 
        string fieldName = fieldAccessors[fieldAccessors.Length - 1];

        // Hide the data member if its name ends with 'ID'.
        if(fieldName.EndsWith("ID")) {
            return null;
        }

        // Hide the 'Products' table, because its fields are accessible 
        // via the 'CategoriesProducts' table only.
        if(fieldAccessors[0].StartsWith("Products")) {
            return null;
        }

        // Insert spaces between separate words of a field name.
        return ChangeNames(fieldName);
    }
    public string ChangeNames(string name) {
        string result = string.Empty;
        bool isPrevLow = false;

        foreach(char symb in name) {
            // Check if a character is of upper case.
            // To avoid spaces inside abbreviations, 
            // check if the previous character is of upper case, too.
            if(Char.IsUpper(symb) && isPrevLow) {
                result += " " + symb;
            }
            else {
                result += symb;
            }
            isPrevLow = Char.IsLower(symb);
        }
        return result;
    }
// ...
}
See Also