Skip to main content

Unbound Mode

  • 2 minutes to read

This topic explains the basics of how to handle the data in unbound mode.

In unbound mode, a tree list doesn’t connect to any data source. The View is populated with the data programmatically.

The example below is taken from the ExpressQuantumTreeList Features demo.

Creating and initializing columns

Columns within a TreeList control can be created at design or runtime. To create columns at design time, use the Component Editor. Refer to the Create And Delete Columns help topic for details.

If a TreeList is not connected to a data source, columns must be created manually. For each column, it is required to set the appropriate data type. Use the DataBinding.ValueTypeClass property for this purpose. See the TcxValueType class topic for the types available.

The following example shows how to specify the value type for four columns of the TreeList control.

clnDepartment.DataBinding.ValueTypeClass := TcxStringValueType;
  clnBudget.DataBinding.ValueTypeClass := TcxCurrencyValueType;
  clnLocation.DataBinding.ValueTypeClass := TcxStringValueType;
  clnPhone1.DataBinding.ValueTypeClass := TcxStringValueType;
  clnPhone2.DataBinding.ValueTypeClass := TcxStringValueType;

Loading data

The Values property of the node object allows you to get/set values of a particular data cell. It requires a column index to be supplied. However, on initialization you may use the node’s AssignValues method that allows the values for the all cells to be set in one operation by using an open array. In our demo, we are using the AssignValues method.

procedure TForm1.InitData;
   function AddNode(AParent: TcxTreeListNode; const AValues: Array of Variant; AImageIndex: Integer): TcxTreeListNode;
   begin
     Result := TreeList.AddChild(AParent);
     Result.AssignValues(AValues);
     Result.Imageindex := AImageIndex;
   end;
var
  ARootNode, ASalesMarketingNode: TcxTreeListNode;
begin
  ARootNode := AddNode(nil, ['Corporate Headquarters', 1000000, 'Monterey', '(408) 555-1234', '(408) 555-1234'], 8);
  ASalesMarketingNode := AddNode(ARootNode, ['Sales and Marketing', 22000, 'San Francisco', '(415) 555-1234', '(415) 555-1234'], 1);
  AddNode(ASalesMarketingNode, ['Field Office: Canada', 500000, 'Toronto', '(416) 677-1000', '(416) 555-1234'], 4);
  AddNode(ASalesMarketingNode, ['Field Office: East Coast', 500000, 'Boston', '(617) 555-1234', '(415) 555-1234'], 4);
end;

This is the code execution result: