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.v19.1.Core.dll
Declaration
Property Value
Type | Default | Description |
---|---|---|
String | String.Empty | A String value that specifies the name of a data field. |
Remarks
The FieldName or ColumnBase.Binding (that also sets FieldName internally) properties must be defined for every GridControl column.
Note
When working with data structures that contain Dynamic Objects, use the ColumnBase.Binding property instead of FieldName.
Important
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.
Tip
Topics:
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-create-unbound-columns-e1503.
<Window x:Class="DXGrid_UnboundColumns.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
Title="Window1"
Height="300"
Width="552">
<Grid>
<dxg:GridControl x:Name="grid" CustomUnboundColumnData="grid_CustomUnboundColumnData">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="ProductName" />
<dxg:GridColumn FieldName="UnitPrice">
<dxg:GridColumn.EditSettings>
<dxe:TextEditSettings DisplayFormat="c2" />
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
<dxg:GridColumn FieldName="UnitsOnOrder" />
<dxg:GridColumn FieldName="Total" UnboundType="Boolean" ReadOnly="True">
<dxg:GridColumn.EditSettings>
<dxe:TextEditSettings DisplayFormat="c2" />
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True"/>
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</Window>
using System;
using System.Windows;
using DevExpress.Xpf.Grid;
namespace DXGrid_UnboundColumns {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
grid.ItemsSource = new dsProductsTableAdapters.ProductsTableAdapter().GetData();
}
private void grid_CustomUnboundColumnData(object sender, GridColumnDataEventArgs e) {
if (e.IsGetData) {
int price = Convert.ToInt32(e.GetListSourceFieldValue("UnitPrice"));
int unitsOnOrder = Convert.ToInt32(e.GetListSourceFieldValue("UnitsOnOrder"));
e.Value = price * unitsOnOrder;
}
}
}
}
Related GitHub Examples
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.