Skip to main content
A newer version of this page is available. .

GridColumn.UnboundType Property

Gets or sets the data type and binding mode of the column.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v18.2.dll

Declaration

[DXCategory("Data")]
[DefaultValue(UnboundColumnType.Bound)]
[XtraSerializableProperty]
public UnboundColumnType UnboundType { get; set; }

Property Value

Type Default Description
UnboundColumnType **Bound**

A UnboundColumnType enumeration value representing the data type and binding mode of the column.

Available values:

Name Description
Bound

Indicates that the column is bound to a field in the control’s underlying data source. The type of data this column contains is determined by the bound field.

Integer

Indicates that the column is unbound and it contains integer values (the Int32 type).

Decimal

Indicates that the column is unbound and it contains decimal values (the Decimal type).

DateTime

Indicates that the column is unbound and it contains date/time values (the DateTime type).

String

Indicates that the column is unbound and it contains string values (the String type).

Boolean

Indicates that the column is unbound and it contains Boolean values (the Boolean type).

Object

Indicates that the column is unbound and it contains values of any type. A TextEdit editor is assigned for the in-place editing of such a column.

Remarks

The Grid Control supports unbound columns. These are columns which aren’t bound to any field in the grid’s data source which is specified by the GridControl.DataSource and GridControl.DataMember properties. Data for unbound columns can be provided using one of two methods:

  • setting a formula (string expression) to the GridColumn.UnboundExpression property. In expressions, you can refer to other columns, and use various functions and operators. See Expressions, to learn about the syntax.
  • handling the ColumnView.CustomUnboundColumnData event. This event can also be used to save any changes made by an end-user in unbound columns via the grid.

To make a column unbound, set its UnboundType property to a UnboundColumnType value that corresponds to the type of data the column will display. For example, if the column is supposed to display integer values, set the UnboundType property to UnboundColumnType.Integer. The data type specified by the UnboundType property determines which editor should be used, by default, to edit the column’s values. In addition, it also determines how values are aligned within the column and which sorting and validity rules should be applied to this column. See the UnboundColumnType topic for information on the available data types for unbound columns.

If the column’s UnboundType property is set to UnboundColumnType.Bound it’s assumed that this column is not unbound and it is bound to a specific field in the data source, specified by the GridColumn.FieldName property.

Note

The UnboundType property must be set after the column has been added to the ColumnView.Columns collection.

For unbound columns, you need to specify unique field names via the GridColumn.FieldName property.

See Unbound Columns to learn more.

Example

Assume that the Grid Control is bound to a table that contains the “Quantity”, “UnitPrice” and “Discount” columns. The example below shows how to add an unbound column to the grid to display the amount of each order according to the expression: QuantityUnitPrice(1-Discount).

The result is displayed below:

CD_UnboundColumns_example

For another example which illustrates working with unbound columns, see the Unbound Columns tutorial.

using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;

private void Form1_Load(object sender, System.EventArgs e) {
   // ...
   gridControl1.ForceInitialize();

   // Create an unbound column.
   GridColumn unbColumn = gridView1.Columns.AddField("Total");
   unbColumn.VisibleIndex = gridView1.Columns.Count;
   unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
   // Disable editing.
   unbColumn.OptionsColumn.AllowEdit = false;
   // Specify format settings.
   unbColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
   unbColumn.DisplayFormat.FormatString = "c";
   // Customize the appearance settings.
   unbColumn.AppearanceCell.BackColor = Color.LemonChiffon;
}

// Returns the total amount for a specific row.
decimal getTotalValue(GridView view, int listSourceRowIndex) {
    decimal unitPrice = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "UnitPrice"));
    decimal quantity = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Quantity"));
    decimal discount = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Discount"));
    return unitPrice * quantity * (1 - discount);
}

// Provides data for the Total column.
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) {
   GridView view = sender as GridView;
   if (e.Column.FieldName == "Total" && e.IsGetData) e.Value = 
     getTotalValue(view, e.ListSourceRowIndex);
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the UnboundType 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.

See Also