windowsforms-120612-common-features-behaviors-breadcrumb-behavior.md
This Behavior allows you to implement breadcrumb navigation within the TreeList‘s hierarchy. This navigation is provided by a separate BreadCrumbEdit control.
The Breadcrumb Behavior pairs the TreeList and BreadCrumbEdit controls. In this pairing mode, the BreadCrumbEdit automatically populates its contents based on the bound TreeList’s hierarchy. The BreadCrumbEdit control’s selection is then in sync with the TreeList’s focused node.
Demo: Explorer(Virtual Tree) module in the XtraTreeList MainDemo
Create Behavior
Ensure that your form already contains TreeList and BreadCrumbEdit controls.
From the TreeList’s smart tag, select Add Behaviors…. This opens the Behaviors dialog allowing you to add BreadCrumbBehavior.
Set up the created BreadCrumbBehavior by specifying the following settings.
behaviorManager1.Attach<BreadCrumbBehavior>(treeList1, behavior => {
behavior.Properties.DisplayMember = "DEPARTMENT";
behavior.Properties.BreadCrumbControl = breadCrumbEdit1;
});
BehaviorManager1.Attach(Of DevExpress.XtraEditors.BreadCrumbBehavior.BreadCrumbBehavior)(TreeList1, Sub(behavior)
behavior.Properties.DisplayMember = "DEPARTMENT"
behavior.Properties.BreadCrumbControl = BreadCrumbEdit1
End Sub)
Optional Settings and Events
ValueMemberSpecifies the field whose contents are used to initialize BreadCrumbEdit item values (BreadCrumbNode.Value). To ensure correct item identification, item values (if specified) must be unique among sibling nodes. You can also provide unique item values by handling the CustomItemContents event.BreadCrumbEvents.CustomItemContents event
Allows you to customize the display text, image, and other settings of BreadCrumbEdit items. To access this event, create a BreadCrumbBehavior at design time. The designer will generate a BreadCrumbEvents object for the behavior.
private void breadCrumbEvents1_CustomItemContents(object sender, CustomItemContentsEventArgs e) {
TreeListNode tlNode = e.Item.Tag as TreeListNode;
if (tlNode == null)
return;
// Specify a custom caption for root node items.
if (tlNode.ParentNode == null)
e.Item.Caption = "Home";
else
e.Item.Caption = tlNode.GetDisplayText("Department");
}
Private Sub breadCrumbEvents1_CustomItemContents(sender As Object, e As CustomItemContentsEventArgs) Handles breadCrumbEvents1.CustomItemContents
Dim tlNode As TreeListNode = TryCast(e.Item.Tag, TreeListNode)
If tlNode Is Nothing Then
Return
End If
' Specify a custom caption for root node items.
If tlNode.ParentNode Is Nothing Then
e.Item.Caption = "Home"
Else
e.Item.Caption = tlNode.GetDisplayText("Department")
End If
End Sub