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

GridColumn.UnboundType Property

Specifies whether this column is unbound and, if yes, the type of data it stores.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v19.1.dll

Declaration

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

Property Value

Type Default Description
UnboundColumnType **Bound**

A UnboundColumnType enumeration value that specifies 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

If the UnboundType property equals Bound, the column displays values stored in a related data source field. Otherwise, the column is unbound and displays custom values. To create an unbound column in code, do the following.

  • Create a new GridColumn object and add it to the ColumnView.Columns collection.
  • Set the UnboundType property according to the data type this column should display. For instance, use the UnboundColumnType.Integer value if a column cells should display integer values.
  • Assign any value to the column GridColumn.FieldName. A field name must be unique and match neither other columns’ field names, nor names of data source fields.

To populate an unbound column with values, do one of the following.

  • If you need to display values calculated from other columns’ values, assign the required expression to the GridColumn.UnboundExpression property. Note that since cell values are calculated automatically, users cannot edit them. For the expression syntax, refer to the Expressions article.

  • To display custom values, handle the ColumnView.CustomUnboundColumnData event. Columns populated in this way remain editable.

See Unbound Columns for more info.

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