WebDataTree returns multiple selected nodes in single-select mode

This could be a bug in Infragistics WebDataTree control or it could be a very specific scenario (maybe it’s even by design, I don’t know) but here’s a weird behavior that I encountered. Using following code in WebDataTree’s event handler (oh and by the way, tree control is in a single-select mode):

Protected Sub xMyTree_SelectionChanged(ByVal sender As Object, ByVal e As NavigationControls.DataTreeSelectionEventArgs) Handles MyTree.SelectionChanged
   if e.NewSelectedNodes(0).Text = "Some Value"
      'do something with newly selected tree node
   end if
End Sub

I intended to use newly selected node to perform some operations. To my surprise e.NewSelectedNodes(0) referred to previously selected node (despite the name of the property) and newly selected value were located in e.NewSelectedNodes(1)! So the quick workaround was to use slightly modified code:

Protected Sub xMyTree_SelectionChanged(ByVal sender As Object, ByVal e As NavigationControls.DataTreeSelectionEventArgs) Handles MyTree.SelectionChanged
   if e.NewSelectedNodes(e.NewSelectedNodes.Count-1).Text = "Some Value"
      'do something with newly selected tree node
   end if
End Sub

This way it will always get latest selected node and the solution is universal. If the bug described above occurs – code will grab e.NewSelectedNodes(1) (because Count = 2). If the tree behaves as expected – code will get grab e.NewSelectedNodes(0) (because Count = 1)

2 replies on “WebDataTree returns multiple selected nodes in single-select mode”

  1. Yuriy,

    I have seen that when the WebDataTree is sorted, the NewSelectedNodes collection is in the order from the top of the tree down, so your code will always select the LOWEST node.

    If wdtPipeline.SelectionType = NodeSelectionTypes.Single Then
    e.OldSelectedNodes.Item(0).Selected = False
    e.NewSelectedNodes.Remove(e.OldSelectedNodes.Item(0))
    End If
    Dim newTarget As Infragistics.Web.UI.NavigationControls.DataTreeNode = e.NewSelectedNodes.Item(0)

    This will remove the Old selected node from the list of NewSelectedNodes and deselect it as well.

Leave a Reply

Your email address will not be published. Required fields are marked *