Working with the TaskResults control


In this topic


Creating and modifying contents of a TaskResults control

The TaskResults control works with results from tasks. However, you can explicitly define parent and child node content to take advantage of the context menus and functionality in a TaskResults control without using a task.
Nodes in a TaskResults control are essentially TreeViewPlusNode objects. While a TreeViewPlusNode provides the most fine-grained control over node content, some types are provided to construct content for you. The following are the available and different result object types:
  • SimpleTaskResult
  • DataSet
  • TaskResultNode
These object types can be used with the DisplayResults method on a TaskResults control to add content. The following discusses each result object type and includes screen shots and code examples of runtime display results.

SimpleTaskResult object type

A SimpleTaskResult is a Web Application Developer Framework (ADF) specific object type used to create a node with simple text display in one parent and one child node. The parent node content is the heading and the child node content is the detail. This object type is used for simple message output in a TaskResults control. 
The following code example creates a simple parent and child node in a TaskResults control with the string values of "HEADING" and "DETAIL," respectively.
Some parameters in the DisplayResults method are null because the node content is not related to a task. The TaskResults control, TaskResults1, is assumed to be available.
The following screen shot shows the results of the associated code example:
[C#]
SimpleTaskResult str = new SimpleTaskResult("HEADING", "DETAIL");
TaskResults1.DisplayResults(null, null, null, str);

DataSet object type

A DataSet is a .NET Framework object type used for data storage and maintenance. As a versatile type within .NET, a DataSet provides a number of functionality benefits and enhancements to manage data. 
As a standard ADO.NET data type, .NET developers are familiar with and might already be utilizing DataSets and their contents, such as DataTables, DataColumns, and DataRows. DataSets can be used by the TaskResults control directly, without converting between types. As a result, DataSets can be integrated to display with Web ADF applications using the TaskResults control. 
The following code example shows how to create a DataSet with contents and display it in a TaskResults control. The DataSet instance is included in a call to the DisplayResults method. The TaskResults control, TaskResults1, is assumed to be available.
The following screen shot shows the results of the associated code example:
[C#]
DataTable dt = new DataTable("table1");
DataColumn dc1 = new DataColumn("column11");
DataColumn dc2 = new DataColumn("column12");
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
DataRow dr1 = dt.NewRow();
dr1[dc1] = "value11";
dr1[dc2] = "value12";
dt.Rows.Add(dr1);
DataTable dt2 = new DataTable("table2");
DataColumn dc21 = new DataColumn("column21");
DataColumn dc22 = new DataColumn("column22");
dt2.Columns.Add(dc21);
dt2.Columns.Add(dc22);
DataRow dr21 = dt2.NewRow();
dr21[dc21] = "value21";
dr21[dc22] = "value22";
dt2.Rows.Add(dr21);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.Tables.Add(dt2);
TaskResults1.DisplayResults(null, null, null, ds);

TaskResultsNode object type

A TaskResultsNode is a Web ADF specific object type used for fine-grained control over node display and actions within a TaskResults control. A TaskResults control generates a collection of TaskResultNodes to display the contents of a DataSet. The TaskResultNodes subclass and TreeViewPlusNode are utilized when explicit control over node properties is required.
The following code example shows how to create two TaskResultNodes, one parent and one child. The style properties of the child node are modified to render the text using the color red. The SetupTaskResultNode method configures the TaskResultNode and child nodes to include a context menu at runtime with the option to remove the node. This is automatically provided with SimpleResultNode and DataSet result types. The TaskResults control, TaskResults1, is assumed to be available.
The following screen shot shows the results of the associated code example:
[C#]
TaskResultNode trn_parent = new TaskResultNode("Parent Node");
TaskResultNode trn_child = new TaskResultNode("Child Node");
trn_parent.Nodes.Add(trn_child);
trn_child.TextCellStyleAttributes.Add("color", System.Drawing.ColorTranslator.ToHtml
    (System.Drawing.Color.Red));
TaskResults1.SetupTaskResultNode(null, null, null, trn_parent);
TaskResults1.DisplayResults(null, null, null, trn_parent);
Working with a TaskResultNode means you want fine-grained control over the organization, style, and actions of nodes in a TaskResult control. 
The following code example shows a TaskResultNode created from the DataSet defined in the DataSet object type section. The first level child nodes' text color was changed to "blue." The second level child nodes' font style was changed to "italic." 
The TaskResult control maintains a node collection that can be used to insert a TaskResultNode anywhere in the collection. A TaskResults control, TaskResults1, is assumed to be available.
The following screen shot shows the results of the associated code example:
[C#]
TaskResultNode trn_ds = TaskResults1.CreateTaskResultNode(null, null, null, ds, true,
    true);
foreach (TreeViewPlusNode tvpn in trn_ds.Nodes)
{
    tvpn.TextCellStyleAttributes.Add("color", System.Drawing.ColorTranslator.ToHtml
        (System.Drawing.Color.Blue));
    foreach (TreeViewPlusNode tvpn1 in tvpn.Nodes)
    {
        tvpn1.TextCellStyleAttributes.Add("font-style", "italic");
        tvpn1.Text = tvpn1.Text + "_new";
    }
}

TaskResults1.Nodes.Insert(0, trn_ds);


See Also:

TaskResults control