Back to Devexpress

ColumnBase.FieldName Property

wpf-devexpress-dot-xpf-dot-grid-dot-columnbase-f2ae6172.md

latest13.5 KB
Original Source

ColumnBase.FieldName Property

Gets or sets the name of the database field assigned to this column. This is a dependency property.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
[DefaultValue("")]
public virtual string FieldName { get; set; }
vb
<DefaultValue("")>
Public Overridable Property FieldName As String

Property Value

TypeDefaultDescription
StringString.Empty

A String value that specifies the name of a data field.

|

Remarks

Use the FieldName property to bind columns to data source properties.

Note

When you use a custom CellTemplate, follow the recommendations below to automatically bind cell values to the property specified by FieldName:

When you use the ColumnBase.Binding property to bind a column to a data field, the GridControl initializes the FieldName property with a value based on the specified binding expression.

If your field name has a complex path (like “ClientClasses.Count“) and you want the GridControl to reflect changes made in these nested properties, set the DataControlBase.DetectNestedPropertyChanges property to true.

Tip

Topics :

Important

When working with data structures that contain Dynamic Objects, use the ColumnBase.Binding property instead of FieldName.

Do not bind multiple columns to the same field in the data base. Only a single column can be bound to a specific field in the database. If you need to create another column bound to the same field, create a new unbound column, and set its FieldName property to a unique string. Then, handle the GridControl.CustomUnboundColumnData event to populate this column with the same data as the first column.

Example

This example shows how to add an unbound column to the GridControl. This column should display the total price, calculated as follows: UnitPrice * UnitsOnOrder.

View Example: How to Create Unbound Columns

xaml
<dxg:GridControl x:Name="grid"
                 CustomUnboundColumnData="grid_CustomUnboundColumnData">
    <dxg:GridColumn FieldName="CompanyName"/>
    <dxg:GridColumn FieldName="City"/>
    <dxg:GridColumn FieldName="UnitPrice">
        <dxg:GridColumn.EditSettings>
            <dxe:TextEditSettings DisplayFormat="c2"/>
        </dxg:GridColumn.EditSettings>
    </dxg:GridColumn>
    <dxg:GridColumn FieldName="Quantity"/>
    <dxg:GridColumn FieldName="Total" UnboundDataType="{x:Type sys:Decimal}" ReadOnly="True">
        <dxg:GridColumn.EditSettings>
            <dxe:TextEditSettings DisplayFormat="c2"/>
        </dxg:GridColumn.EditSettings>
    </dxg:GridColumn>
    <dxg:GridControl.View>
        <dxg:TableView AutoWidth="True"/>
    </dxg:GridControl.View>
</dxg:GridControl>
cs
void grid_CustomUnboundColumnData(object sender, GridColumnDataEventArgs e) {
    if(e.IsGetData) {
        int price = Convert.ToInt32(e.GetListSourceFieldValue(nameof(Product.UnitPrice)));
        int quantity = Convert.ToInt32(e.GetListSourceFieldValue(nameof(Product.Quantity)));
        e.Value = price * quantity;
    }
}
vb
Private Sub grid_CustomUnboundColumnData(ByVal sender As Object, ByVal e As GridColumnDataEventArgs)
    If e.IsGetData Then
        Dim price As Integer = Convert.ToInt32(e.GetListSourceFieldValue(NameOf(Product.UnitPrice)))
        Dim quantity As Integer = Convert.ToInt32(e.GetListSourceFieldValue(NameOf(Product.Quantity)))
        e.Value = price * quantity
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the FieldName property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

how-to-bind-wpf-grid-to-data/CS/CodeBehind/EFCore/LocalData/MainWindow.xaml#L12

xml
</dxg:GridControl.View>
<dxg:GridColumn FieldName="Id" IsSmart="True"
                ReadOnly="True" />

wpf-data-grid-implement-crud-operations/CS/CodeBehind/EFCore/PagedAsyncSource/MainWindow.xaml#L25

xml
</dxg:GridControl.View>
<dxg:GridColumn FieldName="Id" IsSmart="True"
                AllowEditing="True" ReadOnly="True" />

wpf-data-grid-process-frequent-data-updates/CS/ChunkAndOptSummariesExample/MainWindow.xaml#L26

xml
<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="Name"/>
    <dxg:GridColumn FieldName="Group" GroupIndex="0"/>

wpf-data-grid-extend-crud-operations/CS/DetailCollectionEditing/MainWindow.xaml#L24

xml
</dxg:GridControl.View>
<dxg:GridColumn FieldName="Id" IsSmart="True" ReadOnly="True" />
<dxg:GridColumn FieldName="FirstName" IsSmart="True" />

wpf-data-grid-bind-to-infiniteasyncsource/CS/InfiniteAsyncSourceSample/MainWindow.xaml#L17

xml
<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="Id" IsSmart="True" AllowEditing="True" Width="*"/>
    <dxg:GridColumn FieldName="Subject" IsSmart="True" AllowEditing="True" Width="2*"/>

wpf-data-grid-change-background-color-for-modified-cells/CS/HighlightChangedCellBehavior.cs#L39

csharp
if (!IsServiceColumn(e.Column)) {
    var fieldName = $"{UnboundColumnPrefix}{e.Column.FieldName}";
    var key = Tuple.Create(e.Row, fieldName);

wpf-data-grid-implement-custom-grouping/CS/CustomGrouping_CodeBehind/MainWindow.xaml.cs#L40

csharp
void OnCustomColumnGroup(object sender, CustomColumnSortEventArgs e) {
    if(e.Column.FieldName != "UnitPrice")
        return;

wpf-data-grid-embed-a-richtextbox-into-grid-cells/CS/Window1.xaml.cs#L17

csharp
private void view_GetActiveEditorNeedsKey(object sender, DevExpress.Xpf.Grid.GetActiveEditorNeedsKeyEventArgs e) {
    if(e.Column.FieldName == "RtfContent") {
        if(e.Key == Key.Enter && !e.Modifiers.HasFlag(ModifierKeys.Control))

wpf-data-grid-filter-column-lookupedit-based-on-value-in-another-column/CS/MainWindow.xaml.cs#L50

csharp
void OnTableViewShownEditor(object sender, EditorEventArgs e) {
    if (e.Column.FieldName != "CityId")
        return;

how-to-specify-navigation-in-custom-cell-editors/CS/NavigationBehavior.cs#L18

csharp
void TableView_ProcessEditorActivationAction(object sender, ProcessEditorActivationActionEventArgs e) {
    if (e.Column.FieldName == nameof(Place.City))
        if (e.ActivationAction == ActivationAction.MouseLeftButtonDown && e.MouseLeftButtonEventArgs.LeftButton == System.Windows.Input.MouseButtonState.Pressed)

wpf-data-grid-change-background-color-for-modified-cells/VB/HighlightChangedCellBehavior.vb#L58

vb
If Not HighlightModifiedCells.ChangedCellsHighlightBehavior.IsServiceColumn(e.Column) Then
    Dim fieldName = $"{HighlightModifiedCells.ChangedCellsHighlightBehavior.UnboundColumnPrefix} {e.Column.FieldName}"
    Dim key = System.Tuple.Create(e.Row, fieldName)

wpf-data-grid-implement-custom-grouping/VB/CustomGrouping_CodeBehind/MainWindow.xaml.vb#L41

vb
Private Sub OnCustomColumnGroup(ByVal sender As Object, ByVal e As CustomColumnSortEventArgs)
    If Not Equals(e.Column.FieldName, "UnitPrice") Then Return
    Dim x As Double = Math.Floor(Convert.ToDouble(e.Value1) / 10)

wpf-data-grid-filter-column-lookupedit-based-on-value-in-another-column/VB/MainWindow.xaml.vb#L75

vb
Private Sub OnTableViewShownEditor(ByVal sender As Object, ByVal e As EditorEventArgs)
    If Not Equals(e.Column.FieldName, "CityId") Then Return
    Dim editor As LookUpEditBase = TryCast(e.Editor, LookUpEditBase)

how-to-specify-navigation-in-custom-cell-editors/VB/NavigationBehavior.vb#L23

vb
Private Sub TableView_ProcessEditorActivationAction(ByVal sender As Object, ByVal e As ProcessEditorActivationActionEventArgs)
    If Equals(e.Column.FieldName, NameOf(Place.City)) Then
        If e.ActivationAction = ActivationAction.MouseLeftButtonDown AndAlso e.MouseLeftButtonEventArgs.LeftButton = System.Windows.Input.MouseButtonState.Pressed Then e.RaiseEventAgain = True

wpf-data-grid-implement-custom-sorting/VB/CustomSorting_CodeBehind/MainWindow.xaml.vb#L48

vb
Private Sub OnCustomColumnSort(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.CustomColumnSortEventArgs)
    If Equals(e.Column.FieldName, "Day") Then
        Dim dayIndex1 As Integer = Me.GetDayIndex(e.Value1)

See Also

Binding Columns to Data Source Fields

ColumnBase Class

ColumnBase Members

DevExpress.Xpf.Grid Namespace