When buidling your own Classification-tree-control you need to locate the Classifications on specific levels. This blog will show how to get them easily using SearchExpression.
Finding the root Classifications
Root Classifications are Classification that have no parents. Finding them using the SearchExpression class can be done by this shorthand: "Parent = null".
| C# |
1
2
3
4
5
6
7
8
9
10
11
|
private ClassificationCollection GetRootClassifications()
{
Application app = new Application();
app.LogOn(Settings.Default.Registration, Settings.Default.AdamUserName, Settings.Default.AdamUserPassword, true, null);
ClassificationCollection rootClassifications = new ClassificationCollection(app);
rootClassifications.Load(new SearchExpression("Parent = null"), "Label");
return rootClassifications;
}
|
An alternative method is the usage of the ClassificationHelper class:
| C# |
1
2
3
4
5
6
7
8
9
10
11
|
private ClassificationCollection GetRootClassifications()
{
Application app = new Application();
app.LogOn(Settings.Default.Registration, Settings.Default.AdamUserName, Settings.Default.AdamUserPassword, true, null);
ClassificationHelper classificationHelper = new ClassificationHelper(app);
ClassificationCollection rootClassifications = classificationHelper.GetChildren(null, null, null); //Args: no parent id, no child filter, no load options.
return rootClassifications;
}
|
Finding the child Classifications
Once the root Classifications have been located, the children can be found using the Id of its parent. The "Parent.Id = [The Parent's Id]" statement will find the child Classifications of any given Classification.
| C# |
1
2
3
4
5
6
7
8
9
10
11
|
private ClassificationCollection GetChildClassifications(Guid parentId)
{
Application app = new Application();
app.LogOn(Settings.Default.Registration, Settings.Default.AdamUserName, Settings.Default.AdamUserPassword, true, null);
ClassificationCollection childClassifications = new ClassificationCollection(app);
childClassifications.Load(new SearchExpression("Parent.Id = " + parentId), "Label");
return childClassifications;
}
|
This can be approached via the ClassificationHelper class as well:
| C# |
1
2
3
4
5
6
7
8
9
10
11
|
private ClassificationCollection GetChildClassifications(Guid parentId)
{
Application app = new Application();
app.LogOn(Settings.Default.Registration, Settings.Default.AdamUserName, Settings.Default.AdamUserPassword, true, null);
ClassificationHelper classificationHelper = new ClassificationHelper(app);
ClassificationCollection childClassifications = classificationHelper.GetChildren(parentId, null, null); //Args: specific parent id, no child filter, no load options.
return childClassifications;
}
|
Lazy loading for Classifications
Getting Classifications can be a performance drain, especially in an environment with a large amount of Classifications and/or a complex security structure. Therefore it's highly recommended to lazy load Classifications into your tree control, meaning only get the ones that the user requests. A down side of this method is that in a typical tree control the plus sign (+) will remain visible next to a Classification node, eventhough the node doesn't contain any children.