IDisplayNameProvider Interface
Provides methods that return custom names for the Field List items.
Namespace: DevExpress.Data
Assembly: DevExpress.Data.v24.1.dll
NuGet Package: DevExpress.Data
Declaration
Related API Members
The following members return IDisplayNameProvider objects:
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:
using System;
using DevExpress.Data;
using DevExpress.DataAccess.Sql;
namespace docCustomDataItemsNames
{
public class MySqlDataSource : SqlDataSource, IDisplayNameProvider
{
public MySqlDataSource() {
}
public MySqlDataSource(SqlDataSource copyFrom) {
this.LoadFromXml(copyFrom.SaveToXml());
}
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' relation 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;
}
}
}