Back to Devexpress

TdxTreeViewNodeCompareEvent Type

vcl-dxtreeview-45bd60ec.md

latest2.5 KB
Original Source

TdxTreeViewNodeCompareEvent Type

The node comparison procedural type.

Declaration

delphi
TdxTreeViewNodeCompareEvent = procedure(Sender: TdxCustomTreeView; ANode1: TdxTreeViewNode; ANode2: TdxTreeViewNode; AData: TdxNativeInt; var ACompare: Integer) of object;

Parameters

NameTypeDescription
SenderTdxCustomTreeView

The Tree View control that raised a node comparison event.

| | ANode1 | TdxTreeViewNode |

The first target tree node.

| | ANode2 | TdxTreeViewNode |

The second target tree node.

| | AData | TdxNativeInt |

Specifies a pointer to additional data for the custom comparison routine.

| | ACompare | Integer |

A result of the comparison.

|

Remarks

The following table explains which ACompare parameter values correspond to specific comparison results:

|

Value

|

Description

| | --- | --- | |

A negative integer value

|

ANode1 is positioned above ANode2.

| |

0

|

ANode1 is “equal” to ANode2. Both nodes retain their positions.

| |

A positive integer value

|

ANode1 is positioned below ANode2.

|

The following OnCompare event handler sorts nodes by captions and places nodes with children at the top of the Tree View:

delphi
procedure TForm1.dxTreeViewControl1Compare(Sender: TdxCustomTreeView; ANode1,
  ANode2: TdxTreeViewNode; AData: NativeInt; var ACompare: Integer);
begin
  if ANode1.HasChildren = ANode2.HasChildren then
    ACompare := CompareStr(ANode1.Caption, ANode2.Caption)
  else
  begin
    if ANode1.HasChildren then
      ACompare := -1
    else
      ACompare := 1;
  end;
end;
cpp
void __fastcall TForm1::dxTreeViewControl1Compare(TdxCustomTreeView *Sender, TdxTreeViewNode *ANode1, 
  TdxTreeViewNode *ANode2, NativeInt AData, int &ACompare);
{
  if (ANode1->HasChildren == ANode2->HasChildren)
    ACompare = ANode1->Caption > ANode2->Caption;
  else
    if (ANode1->HasChildren)
      ACompare = -1;
    else
      ACompare = 1;
}

The Tree View’s OnCompare event references the TdxTreeViewNodeCompareEvent type.

See Also

dxTreeView Unit