TreeView, ASP.NET, VB.NET Selected Node Text Path
Un TreeNode tiene como propiedad el ValuePath, con esa propiedad se puede obtener la ruta de los valores dado un nodo hasta llegar al nodo raíz. Por ejemplo: ---> 0/1/2/3/4
Si, ahora, estás buscando cómo obtener la ruta del text... buscando un TextPath? No hay, qué raro. Si hay un ValuePath, por qué no hicieron un TextPath. En fin, como no hay, hay que hacerlo :P A mi me tocó hacerlo pues lo necesitaba para obtener algo asi como en la siguiente imágen:
Dado un nodo seleccionado, se obtiene la ruta de los text a partir de ahí hasta el nodo raíz. Tiene el formato: Parent - Child1 - Child11 - Child111 ... Si no le colocas el "-" Usará el separador que por defecto pone el lenguaje "/"
El código:
Protected Sub trvListaDePrecios_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles trvListaDePrecios.SelectedNodeChanged
Dim nodo As TreeNode = Me.trvListaDePrecios.SelectedNode
Dim strTextPath As String = nodo.Text
Dim strSeparador As String = "-"
Me.trvListaDePrecios.PathSeparator = CChar(strSeparador)
While Not nodo.Parent Is Nothing
strTextPath = nodo.Parent.Text & " " & Me.trvListaDePrecios.PathSeparator & " " & strTextPath
nodo = nodo.Parent
End While
Dim strValuePath As String = Me.trvListaDePrecios.SelectedNode.ValuePath
Me.prcCargarDatosPopUp(strValuePath, strTextPath.ToUpper())
End Sub
HaPPy CoDiNg =)

No comments:
Post a Comment