xtrareports-400328-desktop-reporting-wpf-reporting-end-user-report-designer-for-wpf-api-and-customization-use-query-builder-light-mode.md
The Query Builder Light mode allows you to specify custom names for tables and columns. The Query Builder does not display the resulting SQL query and disables column expressions in this mode because these options use actual data member names.
This document describes how to enable the Query Builder Light mode and customize table and column names in it.
Set the QueryBuilderLight property to true to enable the Query Builder Light mode (for instance, in the Window’s Loaded event handler).
using DevExpress.Xpf.DataAccess.DataSourceWizard;
//...
private void Window_Loaded(object sender, RoutedEventArgs e) {
//...
reportDesigner.DataSourceWizardSettings.SqlWizardSettings.QueryBuilderLight = true;
//...
}
Imports DevExpress.Xpf.DataAccess.DataSourceWizard
'...
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
'...
reportDesigner.DataSourceWizardSettings.SqlWizardSettings.QueryBuilderLight = True
'...
End Sub
Alternatively, you can use the following XAML code to enable this mode.
<Window ...
xmlns:dxrud="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesigner"
xmlns:dxda="http://schemas.devexpress.com/winfx/2008/xaml/dataaccess">
<dxrud:ReportDesigner x:Name="reportDesigner">
<dxrud:ReportDesigner.DataSourceWizardSettings>
<dxda:DataSourceWizardSettings SqlWizardSettings="{dxda:SqlWizardSettings QueryBuilderLight=True}" />
</dxrud:ReportDesigner.DataSourceWizardSettings>
</dxrud:ReportDesigner>
</Window>
This image illustrates the result.
The Query Builder Light mode allows you to implement the IDisplayNameProvider interface to customize table and column names.
This example demonstrates how to add a space to table or column names in the IDisplayNameProvider.GetFieldDisplayName method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.Data;
//...
public partial class MainWindow : Window
{
//...
private void Window_Loaded(object sender, RoutedEventArgs e) {
// Enable the Query Builder Light mode.
reportDesigner.DataSourceWizardSettings.SqlWizardSettings.QueryBuilderLight = true;
// Register the customization service type.
reportDesigner.ServicesRegistry.Add(new TypeEntry() { ServiceType = typeof(IDisplayNameProvider), ConcreteType = typeof(DisplayNameProvider) });
}
}
class DisplayNameProvider : IDisplayNameProvider {
// Substitute the default data source name
// with a custom one.
public string GetDataSourceDisplayName() {
return "Northwind Traders";
}
public string GetFieldDisplayName(string[] fieldAccessors) {
// Get a field or table name from the data source.
string fieldName = fieldAccessors[fieldAccessors.Length - 1];
// Insert spaces between words in 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 uppercase.
// Check if the previous character is uppercase
// to avoid spaces inside abbreviations.
if (Char.IsUpper(symb) && isPrevLow) {
result += " " + symb;
}
else {
result += symb;
}
isPrevLow = Char.IsLower(symb);
}
return result;
}
//...
}
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports DevExpress.Data
'...
Partial Public Class MainWindow
Inherits Window
'...
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Enable the Query Builder Light mode.
reportDesigner.DataSourceWizardSettings.SqlWizardSettings.QueryBuilderLight = True
' Register the customization service type.
reportDesigner.ServicesRegistry.Add(New TypeEntry() With {.ServiceType = GetType(IDisplayNameProvider), .ConcreteType = GetType(DisplayNameProvider)})
End Sub
End Class
Friend Class DisplayNameProvider
Implements IDisplayNameProvider
' Substitute the default data source name
' with a custom one.
Public Function GetDataSourceDisplayName() As String
Return "Northwind Traders"
End Function
Public Function GetFieldDisplayName(ByVal fieldAccessors() As String) As String
' Get a field or table name from the data source.
Dim fieldName As String = fieldAccessors(fieldAccessors.Length - 1)
' Insert spaces between words in 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 uppercase.
' Check if the previous character is uppercase
' to avoid spaces inside abbreviations.
If Char.IsUpper(symb) AndAlso isPrevLow Then
result &= " " & symb
Else
result &= symb
End If
isPrevLow = Char.IsLower(symb)
Next symb
Return result
End Function
'...
The following image illustrates customization results: