Skip to main content
Tab

Collection<T>.ForEach(Action<T>) Method

Performs the specified action on each element of the current collection.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public Collection<T> ForEach(
    Action<T> action
)

Parameters

Name Type Description
action Action<T>

The Action<T> action to perform on each element of the collection.

Returns

Type Description
Collection<T>

A collection of elements that have been processed by the specified action.

Remarks

The ForEach method individually passes elements of the current collection to the specified action, and returns a collection of elements that have been processed by the action.

Example

The code sample below demonstrates how to apply different style settings, specified in data source custom attributes, to treeview nodes using ForEach method. The image below shows the result.

ForEach

using DevExpress.Web.ASPxTreeView;
...
protected void ASPxTreeView1_DataBound(object sender, EventArgs e) {
     ASPxTreeView1.Nodes.ForEach(SetColor);
}
private static void SetColor(TreeViewNode node) {
     System.Xml.XmlNode dataNode = ((node.DataItem as IHierarchyData).Item as System.Xml.XmlNode);
     node.TextStyle.ForeColor = System.Drawing.Color.FromName(dataNode.Attributes["Color"].Value);
}
See Also