corelibraries-devexpress-dot-data-cb0f9b3e.md
Provides methods that return custom names for the Field List items.
Namespace : DevExpress.Data
Assembly : DevExpress.Data.v25.2.dll
NuGet Package : DevExpress.Data
public interface IDisplayNameProvider
Public Interface IDisplayNameProvider
The following members return IDisplayNameProvider objects:
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.
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:
View Example: How to provide custom names for the Field List data items
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;
}
}
}
Imports DevExpress.Data
Imports DevExpress.DataAccess.Sql
Namespace docCustomDataItemsNames
Public Class MySqlDataSource
Inherits SqlDataSource
Implements IDisplayNameProvider
Public Sub New()
End Sub
Public Sub New(ByVal copyFrom As SqlDataSource)
LoadFromXml(copyFrom.SaveToXml())
End Sub
Private Function GetDataSourceDisplayName() As String Implements IDisplayNameProvider.GetDataSourceDisplayName
' Substitute the default datasource display name
' with a custom one.
Return "Northwind Traders"
End Function
Private Function GetFieldDisplayName(ByVal fieldAccessors As String()) As String Implements IDisplayNameProvider.GetFieldDisplayName
' Get a field name form the data member's name.
Dim fieldName As String = fieldAccessors(fieldAccessors.Length - 1)
' Hide the data member if its name ends with 'ID'.
If fieldName.EndsWith("ID") Then
Return Nothing
End If
' Hide the 'Products' table, because its fields are accessible
' via the 'CategoriesProducts' relation only.
If fieldAccessors(0).StartsWith("Products") Then
Return Nothing
End If
' Insert spaces between separate words of a field name.
Return ChangeNames(fieldName)
End Function
Public Function ChangeNames(ByVal name As String) As String
Dim result As String = String.Empty
Dim isPrevLow As Boolean = False
For Each symb As Char 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) AndAlso isPrevLow Then
result += " " & symb
Else
result += symb
End If
isPrevLow = Char.IsLower(symb)
Next
Return result
End Function
End Class
End Namespace
See Also