Back to Devexpress

TreeListHtmlDataCellEventArgs Class

aspnet-devexpress-dot-web-dot-aspxtreelist-871a1227.md

latest4.7 KB
Original Source

TreeListHtmlDataCellEventArgs Class

Provides data for the ASPxTreeList.HtmlDataCellPrepared event.

Namespace : DevExpress.Web.ASPxTreeList

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

NuGet Package : DevExpress.Web

Declaration

csharp
public class TreeListHtmlDataCellEventArgs :
    EventArgs
vb
Public Class TreeListHtmlDataCellEventArgs
    Inherits EventArgs

TreeListHtmlDataCellEventArgs is the data class for the following events:

Remarks

The following example illustrates how to hide the tree list’s parent nodes cell content.

MVC:

css
.HideCell { 
    visibility: hidden;
}
csharp
settings.HtmlCommandCellPrepared = (sender, e) =>
{
    var tl = (MVCxTreeList)sender;
    if (tl.FindNodeByKeyValue(e.NodeKey).ChildNodes.Count > 0)
        e.Cell.CssClass = "HideCell";
    };
settings.HtmlDataCellPrepared = (sender, e) =>
{
    var tl = (MVCxTreeList)sender;
    if (e.Column.FieldName != "From") {
        if (tl.FindNodeByKeyValue(e.NodeKey).ChildNodes.Count > 0)
            e.Cell.CssClass = "HideCell";
    }
};
...
vb
Private Sub SurroundingSub()
    settings.HtmlCommandCellPrepared = Function(sender, e)
    Dim tl = CType(sender, MVCxTreeList)
        If tl.FindNodeByKeyValue(e.NodeKey).ChildNodes.Count > 0 Then e.Cell.CssClass = "HideCell"
    End Function

    settings.HtmlDataCellPrepared = Function(sender, e)
    Dim tl = CType(sender, MVCxTreeList)
        If e.Column.FieldName <> "From" Then
            If tl.FindNodeByKeyValue(e.NodeKey).ChildNodes.Count > 0 Then e.Cell.CssClass = "HideCell"
        End If
    End Function
End Sub
...

Example

This example shows how to paint individual data cells and entire nodes depending upon the ASPxTreList’s data. The ASPxTreeList.HtmlDataCellPrepared event is handled to custom paint budgets that are greater than $1,000,000.

The ASPxTreeList.HtmlRowPrepared event is handled to custom paint departments located at Monterey.

The image below shows the result:

csharp
using System.Drawing;

protected void treeList_HtmlRowPrepared(object sender, TreeListHtmlRowEventArgs e) {
    if(Object.Equals(e.GetValue("Location"), "Monterey"))
        e.Row.BackColor = Color.FromArgb(211, 235, 183);
}

protected void treeList_HtmlDataCellPrepared(object sender, TreeListHtmlDataCellEventArgs e) {
    if(e.Column.Name == "budget") {
        decimal value = (decimal)e.CellValue;
        e.Cell.BackColor = GetBudgetColor(value);
        if(value > 1000000M)
            e.Cell.Font.Bold = true;
    }
}
vb
Imports System.Drawing

Protected Sub treeList_HtmlRowPrepared(ByVal sender As Object, ByVal e As TreeListHtmlRowEventArgs)
   If Object.Equals(e.GetValue("Location"), "Monterey") Then
      e.Row.BackColor = Color.FromArgb(211, 235, 183)
   End If
End Sub

Protected Sub treeList_HtmlDataCellPrepared(ByVal sender As Object,_
ByVal e As TreeListHtmlDataCellEventArgs)
   If e.Column.Name = "budget" Then
      Dim value As Decimal = CDec(e.CellValue)
      e.Cell.BackColor = GetBudgetColor(value)
      If value > 1000000D Then
         e.Cell.Font.Bold = True
      End If
   End If
End Sub

Inheritance

Object EventArgs TreeListHtmlDataCellEventArgs

See Also

TreeListHtmlDataCellEventArgs Members

Tree List Appearance Customization

How to: Implement Conditional Formatting

Tree List

DevExpress.Web.ASPxTreeList Namespace