bool SearchEmployee(object data) { if(data is Employee) { Employee employee = (Employee)data; if(employee.FirstName == "John") { return true; } } return false; }
This topic demonstrates how to implement search in an organization chart.
The topic is organized as follows:
A node of the xamOrgChart™ control is included in the search results if its underlying data fulfills certain conditions. The conditions are specified using a method delegate or a lambda expression. The search results are represented as a collection of OrgChartNode objects.
There are two ways to implement searching in nodes:
using a method delegate
using a Lambda Expression
The rest of the topic deals with them in detail.
When using a method delegate, you define the delegate first and then use it to perform the search.
Define a search condition matching the ConditionMethod delegate:
In C#:
bool SearchEmployee(object data) { if(data is Employee) { Employee employee = (Employee)data; if(employee.FirstName == "John") { return true; } } return false; }
In Visual Basic:
Function SearchEmployee(data As Object) As Boolean
If TypeOf data Is Employee Then
Dim employee As Employee = DirectCast(data, Employee)
If employee.FirstName = "John" Then
Return True
End If
End If
Return False
End Function
Perform the search.
In C#:
IEnumerable<OrgChartNode> searchResults = orgChartInstance.Search(SearchEmployee);
In Visual Basic:
Dim searchResults As IEnumerable(Of OrgChartNode) = orgChartInstance.Search(AddressOf SearchEmployee)
When using a lambda expression, the search condition is defined directly in the Search method.
In C#:
IEnumerable<OrgChartNode> searchResults = orgChartInstance.Search(data => { if (data is Employee) { Employee employee = (Employee)data; if (employee.FirstName == "John") { return true; } } return false; });
In Visual Basic:
Dim searchResults As IEnumerable(Of OrgChartNode) = orgChartInstance.Search(Function(data)
If TypeOf data Is Employee Then
Dim employee As Employee = DirectCast(data, Employee)
If employee.FirstName = "John" Then
Return True
End If
End If
Return False
End Function)