windowsforms-devexpress-dot-xtragrid-dot-columns-dot-gridcolumn-251526ce.md
Allows you to make the column unbound, and specify the type of data it stores.
Namespace : DevExpress.XtraGrid.Columns
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DXCategory("Data")]
public Type UnboundDataType { get; set; }
<DXCategory("Data")>
Public Property UnboundDataType As Type
| Type | Description |
|---|---|
| Type |
The type of data to store in the unbound column.
|
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:
UnboundDataType property to the type of values this column should store.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.
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).
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);
}
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Columns
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' ...
GridControl1.ForceInitialize()
' Create an unbound column.
Dim unboundColumn As GridColumn = GridView1.Columns.AddField("Total")
unboundColumn.VisibleIndex = GridView1.Columns.Count
unboundColumn.UnboundDataType = GetType(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)
End Sub
' Return the total amount for a specific row.
Private Function getTotalValue(view As GridView, listSourceRowIndex As Integer) As Decimal
Dim unitPrice As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "UnitPrice"))
Dim quantity As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Quantity"))
Dim discount As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Discount"))
Return unitPrice * quantity * (1 - discount)
End Function
' Specify data for the Total column.
Private Sub GridView1_CustomUnboundColumnData(ByVal sender As Object,
ByVal e As CustomColumnDataEventArgs) Handles GridView1.CustomUnboundColumnData
Dim view As GridView = TryCast(sender, GridView)
If e.Column.FieldName = "Total" AndAlso e.IsGetData Then
e.Value = getTotalValue(view, e.ListSourceRowIndex)
End If
End Sub
See Also