Back to Devexpress

TdxOcNode.GetNext Method

vcl-dxorgchr-dot-tdxocnode-ee622c52.md

latest3.8 KB
Original Source

TdxOcNode.GetNext Method

Returns the next node in the control’s nodes list.

Declaration

delphi
function GetNext: TdxOcNode;

Returns

Type
TdxOcNode

Remarks

Call this function recursively to iterate through the nodes and apply the same changes to them. The function returns nil if the current node is the last in the list.

The following code example shows how to apply the selected node’s appearance settings to all the nodes in the tree structure:

delphi
//This procedure recursively applies the specific node's appearance settings to the other tree nodes, starting from the specified one
procedure MyForm.ApplyStyleToAll(ASourceNode, ACurrentNode: TdxOcNode);
var
  ANodeInfo: TdxOcNodeInfo; // Stores the tree node's appearance settings
  AText: string;
begin
  if(ASourceNode = nil) or (ACurrentNode = nil) then Exit; // Ensures that the following code is executed only in the case of valid parameters
  ASourceNode.GetNodeInfo(ANodeInfo); // Copies the source node's appearance settings
  AText := ASourceNode.Text; // Copies the node's text
  ACurrentNode := ACurrentNode.GetNext; // Obtains the next destination node
  if ACurrentNode = nil then Exit;
  ACurrentNode.Width := ANodeInfo.Width;
  ACurrentNode.Height := ANodeInfo.Height;
  ACurrentNode.Color := ANodeInfo.Color;
  ACurrentNode.Shape := ANodeInfo.Shape;
  ACurrentNode.ImageIndex := ANodeInfo.Index;
  ACurrentNode.ImageAlign := ANodeInfo.IAlign;
  ACurrentNode.ChildAlign := ANodeInfo.Align;
  ACurrentNode.Text := AText; // Assigns the previously copied text to the node
  ApplyStyleToAll(ACurrentNode, ACurrentNode); // Calls the ApplyStyleToAll procedure recursively to apply the same settings to the remaining nodes.
end;
// Pass the selected node as the AsourceNode parameter to apply the appearance settings to all the control's nodes, starting from the first one
  ApplyStyleToAll(dxOrgChart1.Selected, dxOrgChart1.RootNode);
cpp
// This procedure recursively applies the specific node's appearance settings to the other nodes, starting from the specified one
void __fastcall MyForm::ApplyStyleToAll(TdxOcNode *ASourceNode, TdxOcNode *ACurrentNode)
{
  TdxOcNodeInfo ANodeInfo; // Stores the tree node's appearance settings
  UnicodeString AText;
  if ((ASourceNode == NULL) ||(ACurrentNode == NULL)) { return; } // Ensures that the following code is executed for valid parameters only
  ASourceNode->GetNodeInfo(ANodeInfo); //Copies the source node's appearance settings
AText = ASourceNode->Text; // Copies the node's text
  ACurrentNode = ACurrentNode->GetNext(); // Obtains the next destination node
  if (ACurrentNode == NULL) { return; }
  ACurrentNode->Width = ANodeInfo.Width;
  ACurrentNode->Height = ANodeInfo.Height;
  ACurrentNode->Color = ANodeInfo.Color;
  ACurrentNode->Shape = ANodeInfo.Shape;
  ACurrentNode->ImageIndex = ANodeInfo.Index;
  ACurrentNode->ImageAlign = ANodeInfo.IAlign;
  ACurrentNode->ChildAlign = ANodeInfo.Align;
  ACurrentNode->Text = AText; // Copies the node's text
  ApplyStyleToAll(ACurrentNode,ACurrentNode); // Assigns the previously copied text to the node
}
// Pass the selected node as the ASourceNode parameter to aplly its appearance settings to all the control's nodes, starting from the first one.
void __fastcall MyForm::ApplyStyleToAllNodesClick(TObject *Sender)
{
  ApplyStyleToAll(dxOrgChart1->Selected, dxOrgChart1->RootNode);
}

See Also

TdxOcNode.getNextSibling

TdxOcNode.GetNextVisible

TdxOcNode.GetPrev

TdxOcNode Class

TdxOcNode Members

dxorgchr Unit