Hi guys,
I would like to set selected node (or nodes) by databinding (highlight a node as if the user clicked on it)...
I went through the online doco but couldn't find a property to bind to. Any help would be appreciated...
Thanks
Hi Henry,
There is a property called SelectedNodes: public SelectedOrgChartNodesCollection SelectedNodes {get;}
Binding directly to it will not work but you can use something like:
foreach (var node in mySelectedNodes)
{
OrgChart.SelectedNodes.Add(node);
}
You can see a working sample for using this property here.
Please let me know if I can provide any further assistance.
Best,
Ivo
Thanks for the reply Ivo. I just tried what you said. We use customized node object and bind a list of our node objects to the ItemsSource property. The chart displays ok. However, when I tried to set the selected node, the line OrgChart.SelectedNodes.Add(node); has compile error "Argument type "MyNode" is not assignable to parameter type Infragistics.Controls.Maps.OrgChartNode...
Does that mean I need to go through all nodes in the chart and find the one I want and then add it to the SelectedNodes collection? I presume OrgChartNode.Data contains my node. Is that right?
Thanks,
Henry
you are right - you can also use the SearchNode functionality - here is an example.
Thank you again lvo. I tried manually search for the node and it works but the follwoing using Search doesn't work... Can you see anything wrong with the search?
public void SetSelectedNode(string nodeId) { _selectedNodeId = new Guid(nodeId); var searchResult = XamOrgChart.Search(CompareNodeId).SingleOrDefault(); if (searchResult != null) { XamOrgChart.SelectedNodes.Clear(); XamOrgChart.SelectedNodes.Add(searchResult); } }
private bool CompareNodeId(object data) { var node = data as OrgChartNode; if (node != null) { return node.Id == _selectedNodeId; } return false;}
Hello Henry,
I am just checking your progress on the issue. If you require any further assistance please do not hesitate to ask.
I am sorry for the late answer. I have been investigating your issue. In order to search in nodes of xamOrgChart you can use lambda expression or method delegate. Here is a link, where you can find more information about searching in nodes: http://help.infragistics.com/Help/Doc/WPF/2012.1/CLR4.0/html/xamOrgChart_Search_Nodes.html . Please do not hesitate to let me know if you have any further questions.