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

GridControl.CustomUnboundColumnData Event

Enables data to be supplied to unbound columns.

Namespace: DevExpress.WinUI.Grid

Assembly: DevExpress.WinUI.Grid.v21.1.dll

Declaration

public event GridColumnDataEventHandler CustomUnboundColumnData

Event Data

The CustomUnboundColumnData event's data class is GridColumnDataEventArgs. The following properties provide information specific to this event:

Property Description
Column Gets the unbound column currently being processed.
ListSourceRowIndex Gets the index of the record in the data source to which the processed item corresponds.
Row Get a data row which contains the cell currently being processed.
Source Gets the grid control that raised the event.

The event data class exposes the following methods:

Method Description
GetListSourceFieldValue(Int32, String) Returns the value of the specified cell within the specified item in the grid item source.
GetListSourceFieldValue(String) Returns the value of the specified cell within the processed item in the grid item source.

Remarks

Unbound columns are not bound to any field in the data source. In most instances, data for unbound columns is obtained from a custom data source or is calculated based upon the values of bound columns. To provide data for unbound columns, handle the CustomUnboundColumnData event.

Example

The following code sample shows how to add an unbound column to the GridControl.

<Page
    x:Class="Unbound_Columns.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Unbound_Columns"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Grid="using:DevExpress.WinUI.Grid"
    mc:Ignorable="d" >
    <Page.DataContext>
        <local:ViewModel/>
    </Page.DataContext>
    <Grid>
        <Grid:GridControl Name="grid" 
                          ItemsSource="{Binding Products}" 
                          AutoGenerateColumns="False" 
                          CustomUnboundColumnData="grid_CustomUnboundColumnData">
            <Grid:GridControl.Columns>
                <Grid:GridTextColumn FieldName="ProductName"/>
                <Grid:GridTextColumn FieldName="UnitPrice"/>
                <Grid:GridTextColumn FieldName="Quantity"/>
                <Grid:GridTextColumn FieldName="Total" UnboundType="Decimal"/>
            </Grid:GridControl.Columns>
        </Grid:GridControl>
    </Grid>
</Page>
void grid_CustomUnboundColumnData(object sender, DevExpress.WinUI.Grid.GridColumnDataEventArgs e) {
    if (e.IsGetData) {
        int price = Convert.ToInt32(e.GetListSourceFieldValue("UnitPrice"));
        int quantity = Convert.ToInt32(e.GetListSourceFieldValue("Quantity"));
        e.Value = price * quantity;
    }
}
using System.Collections.Generic;
using Microsoft.UI.Xaml.Controls;
using DevExpress.Mvvm;

public class Product {
    public string ProductName { get; set; }
    public string Country { get; set; }
    public string City { get; set; }
    public double UnitPrice { get; set; }
    public int Quantity { get; set; }
}
public class ViewModel : ViewModelBase {
    public ViewModel() {
        List<Product> products = new List<Product> {
            new Product() { ProductName = "Chang", Country = "UK", City = "Cowes", UnitPrice = 19, Quantity = 10 },
            new Product() { ProductName = "Gravad lax", Country = "Italy", City = "Reggio Emilia", UnitPrice = 12.5, Quantity = 16 },
            new Product() { ProductName = "Ravioli Angelo", Country = "Brazil", City = "Rio de Janeiro", UnitPrice = 19, Quantity = 12 },
            new Product() { ProductName = "Tarte au sucre", Country = "Germany", City = "QUICK-Stop", UnitPrice = 22, Quantity = 50 },
            new Product() { ProductName = "Steeleye Stout", Country = "USA", City = "Reggio Emilia", UnitPrice = 18, Quantity = 20 },
            new Product() { ProductName = "Pavlova", Country = "Austria", City = "Graz", UnitPrice = 21, Quantity = 52 },
            new Product() { ProductName = "Longlife Tofu", Country = "USA", City = "Boise", UnitPrice = 7.75, Quantity = 120 },
            new Product() { ProductName = "Alice Mutton", Country = "Mexico", City = "México D.F.", UnitPrice = 21, Quantity = 15 },
            new Product() { ProductName = "Alice Mutton", Country = "Canada", City = "Tsawwassen", UnitPrice = 44, Quantity = 16 }
        };
        Products = products;
    }
    public List<Product> Products { get; }
}

For more information, refer to the following help topic: Unbound Columns.

See Also