Back to Devexpress

TcxTreeListNode.Values Property

vcl-cxtl-dot-tcxtreelistnode.md

latest6.1 KB
Original Source

TcxTreeListNode.Values Property

Provides access to individual column values.

Declaration

delphi
property Values[Index: Integer]: Variant read; write;

Property Value

TypeDescription
Variant

A column value.

|

Remarks

Pass an index as the Index parameter to access the corresponding column value for the node. Corresponding columns are accessible through the Columns property of the parent Tree List control.

Use the ValueCount property to identify the number of values accessible through Values and Texts properties.

Values in Unbound and Bound Data Access Modes

TcxTreeList Unbound Mode. You can use the Values property to specify individual column values for the node as demonstrated in the following code example: Create and Populate Unbound Tree List Controls.TcxDBTreeList Bound Mode. All column values are defined in the underlying dataset (DataController.DataSet). You can use the Values property only to read individual column values for the current node.

Code Example: Create and Populate Unbound Tree List Controls

The following code example creates a TcxTreeList control with three columns and populates it with nodes arranged into a tree-like hierarchy (in unbound mode):

delphi
uses
  cxTL; // Declares the TcxTreeList control and related types
// ...

var
  ATreeList: TcxTreeList;
  ABand: TcxTreeListBand;
  AColumn: TcxTreeListColumn;
  ARootNode, ANode, AChildNode: TcxTreeListNode;
begin
  ATreeList := TcxTreeList.Create(Self); // Creates a TcxTreeList control
  ATreeList.Parent := Self; // Associates the created control with the parent form
  ATreeList.BeginUpdate; // Initiates the following batch operation
  try
    ATreeList.Align := alClient;
    // Create a band and three columns
    ABand := ATreeList.Bands.Add;
    ABand.Caption.Text := 'General Information';
    AColumn := ATreeList.CreateColumn(ABand);
    AColumn.Caption.Text := 'Name';
    AColumn := ATreeList.CreateColumn(ABand);
    AColumn.Caption.Text := 'Distance (000km)';
    AColumn := ATreeList.CreateColumn(ABand);
    AColumn.Caption.Text := 'Period (days)';
    // Create all nodes and assign values
    ARootNode := ATreeList.Add;
    ARootNode.Values[0] := 'Sun';
    ANode := ATreeList.AddNode(nil, ARootNode, nil, tlamAddChild);
    ANode.Values[0] := 'Mercury';
    ANode.Values[1] := 57910;
    ANode.Values[2] := 87.97;
    ANode := ATreeList.AddNode(nil, ARootNode, nil, tlamAddChild);
    ANode.Values[0] := 'Venus';
    ANode.Values[1] := 108200;
    ANode.Values[2] := 224.7;
    ANode := ATreeList.AddNode(nil, ARootNode, nil, tlamAddChild);
    ANode.Values[0] := 'Earth';
    ANode.Values[1] := 149600;
    ANode.Values[2] := 365.26;
    AChildNode := ANode.AddChild;
    AChildNode.Values[0] := 'Moon';
    AChildNode.Values[1] := 384;
    AChildNode.Values[2] := 27.32;
    ARootNode.Expand(True); // Expands all nodes starting from the root level
  finally
    ATreeList.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
  end;
  ATreeList.ApplyBestFit; // Adjusts column width to fit all captions and content in full
end;
cpp
#include "cxTL.hpp" // Declares the TcxTreeList control and related types

// Add the following linker directives to the corresponding CPP source file
#pragma link "cxTL" // Required to use cxTL.hpp declarations
// ...

  TcxTreeList *ATreeList;
  TcxTreeListBand *ABand;
  TcxTreeListColumn *AColumn;
  TcxTreeListNode *ARootNode, *ANode, *AChildNode;
  // ...

  ATreeList = new TcxTreeList(this); // Creates a TcxTreeList control
  ATreeList->Parent = this; // Associates the created control with the parent form
  ATreeList->BeginUpdate(); // Initiates the following batch operation
  try
  {
    ATreeList->Align = alClient;
    // Create a band and three columns
    ABand = ATreeList->Bands->Add();
    ABand->Caption->Text = "General Information";
    AColumn = ATreeList->CreateColumn(ABand);
    AColumn->Caption->Text = "Name";
    AColumn = ATreeList->CreateColumn(ABand);
    AColumn->Caption->Text = "Distance (000km)";
    AColumn = ATreeList->CreateColumn(ABand);
    AColumn->Caption->Text = "Period (days)";
    // Create nodes and assign values
    ARootNode = ATreeList->Add();
    ARootNode->Values[0] = "Sun";
    ANode = ATreeList->AddNode(nullptr, ARootNode, nullptr, tlamAddChild);
    ANode->Values[0] = "Mercury";
    ANode->Values[1] = 57190;
    ANode->Values[2] = 87.97;
    ANode = ATreeList->AddNode(nullptr, ARootNode, nullptr, tlamAddChild);
    ANode->Values[0] = "Venus";
    ANode->Values[1] = 108200;
    ANode->Values[2] = 224.7;
    ANode = ATreeList->AddNode(nullptr, ARootNode, nullptr, tlamAddChild);
    ANode->Values[0] = "Earth";
    ANode->Values[1] = 149600;
    ANode->Values[2] = 365.26;
    AChildNode = ANode->AddChild();
    AChildNode->Values[0] = "Moon";
    AChildNode->Values[1] = 384;
    AChildNode->Values[2] = 27.32;
    ARootNode->Expand(True); // Expands all nodes starting from the root level
  }
  __finally
  {
    ATreeList->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }
  ATreeList->ApplyBestFit(); // Adjusts column width to fit both captions and content in full

See Also

TcxTreeListColumn.DisplayTexts Property

TcxTreeListNode.Texts Property

TcxTreeListNode Class

TcxTreeListNode Members

cxTL Unit