Skip to main content
All docs
V23.2

GridColumn.UnboundDataType Property

Allows you to make the column unbound, and specify the type of data it stores.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v23.2.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

[DXCategory("Data")]
public Type UnboundDataType { get; set; }

Property Value

Type Description
Type

The type of data to store in the unbound column.

Remarks

If the UnboundDataType property is not set to a valid data type (the property’s default value is System.Void), the current column is considered bound to a data source field (GridColumn.FieldName).

To switch a column to unbound mode, do the following:

  • Set the UnboundDataType property to the type of values this column should store.
  • Assign a unique field name to the GridColumn.FieldName property. The field name must not match the field name of another column nor the name of a data source field.
  • Use one of the following techniques to populate the unbound column with data:

If you set a column’s UnboundDataType property to typeof(<object>) (GetType(<object>) in Visual Basic), this column supports sort, group, and filter operations only if the <object> class implements the IComparable interface.

See the following help topic for more information: Unbound Columns.

Example

In the following example, it is assumed that the Grid Control is bound to a table that contains the “Quantity”, “UnitPrice”, and “Discount” columns. The code below adds an unbound column that calculates the total order amount according to the following expression: Quantity * UnitPrice * (1-Discount).

CD_UnboundColumns_example

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

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

    // Create an unbound column.
    GridColumn unboundColumn = gridView1.Columns.AddField("Total");
    unboundColumn.VisibleIndex = gridView1.Columns.Count;
    unboundColumn.UnboundDataType = typeof(decimal);
    // Disable column edit operations.
    unboundColumn.OptionsColumn.AllowEdit = false;
    // Specify format settings.
    unboundColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
    unboundColumn.DisplayFormat.FormatString = "c";
    // Customize appearance settings.
    unboundColumn.AppearanceCell.BackColor = Color.FromArgb(179, 226, 221);
}

// Return 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);
}

// Specify 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);
}
See Also