Back to Devexpress

ASPxTreeList.CustomUnboundColumnData Event

aspnet-devexpress-dot-web-dot-aspxtreelist-dot-aspxtreelist-3d6af3e7.md

latest5.5 KB
Original Source

ASPxTreeList.CustomUnboundColumnData Event

Enables data to be supplied to unbound columns.

Namespace : DevExpress.Web.ASPxTreeList

Assembly : DevExpress.Web.ASPxTreeList.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event TreeListCustomUnboundColumnDataEventHandler CustomUnboundColumnData
vb
Public Event CustomUnboundColumnData As TreeListCustomUnboundColumnDataEventHandler

Event Data

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

PropertyDescription
ColumnGets the processed column.
NodeGets the node currently being processed. Inherited from TreeListNodeEventArgs.
ValueGets the edit value of the cell currently being processed.

Remarks

The CustomUnboundColumnData event is fired for unbound columns only. To create an unbound column, add a new data column to the ASPxTreeList.Columns collection and set its TreeListDataColumn.UnboundType property to an appropriate value, based on the type of data the column is supposed to display. This column’s TreeListDataColumn.FieldName property value must be unique and it must not refer to any field in the ASPxTreeList’s underlying data source.

When the ASPxTreeList is loaded, it raises the CustomUnboundColumnData event for each data cell in unbound columns, allowing you to populate cells with data.

The currently processed cell is identified by the column and node, which can be determined via the TreeListCustomUnboundColumnDataEventArgs.Column and TreeListNodeEventArgs.Node properties, respectively.

The CustomUnboundColumnData event argument provides the TreeListNode.GetValue method, allowing you to get the value of the required cell.

Example

Assume that ASPxTreeList is bound to an “Order Details” data table (NWind data base), which contains “UnitPrice”, “Quantity” and “Discount” fields. There is no field that represents the total sum, as this can be calculated manually as follows: UnitPrice*Quantity*(1-Discount). This example shows how to add an unbound column to the ASPxTreList control to represent the total sum of an order.

The image below shows the result.

csharp
protected void TreeList_CustomUnboundColumnData(object sender, TreeListCustomUnboundColumnDataEventArgs e)
{
    if (e.Column.FieldName == "Total") {
        decimal unitPrice = Convert.ToDecimal(e.Node.GetValue("UnitPrice"));
        decimal quantity = Convert.ToDecimal(e.Node.GetValue("Quantity"));
        decimal discount = Convert.ToDecimal(e.Node.GetValue("Discount"));
        e.Value = unitPrice * quantity * (1 - discount);
    }
}
aspx
<dx:ASPxTreeList runat="server" ID="TreeList" Width="400px" OnCustomUnboundColumnData="TreeList_CustomUnboundColumnData" DataSourceID="SqlDataSource1" 
    SettingsPager-Mode="ShowPager" AutoGenerateColumns="False" KeyFieldName="OrderID">
    <Columns>
        <dx:TreeListTextColumn FieldName="ProductID" VisibleIndex="0" ReadOnly="True">
        </dx:TreeListTextColumn>
        <dx:TreeListTextColumn FieldName="UnitPrice" VisibleIndex="1">
        </dx:TreeListTextColumn>
        <dx:TreeListTextColumn FieldName="Quantity" VisibleIndex="2">
        </dx:TreeListTextColumn>
        <dx:TreeListTextColumn FieldName="Discount" VisibleIndex="3">
        </dx:TreeListTextColumn>
        <dx:TreeListDataColumn FieldName="Total" UnboundType="Decimal"/>
    </Columns>
    <SettingsPager Mode="ShowPager">
    </SettingsPager>
</dx:ASPxTreeList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\nwind.mdb; Persist Security Info=True" 
ProviderName="System.Data.OleDb" SelectCommand="SELECT [ProductID], [UnitPrice], [Quantity], [Discount] FROM [Order Details]"></asp:SqlDataSource>

See Also

Tree List

ASPxTreeList Class

ASPxTreeList Members

DevExpress.Web.ASPxTreeList Namespace