Visual Basic.NET - Llenar Treeview???

 
Vista:

Llenar Treeview???

Publicado por Treeview (8 intervenciones) el 18/07/2008 02:48:32
Saludos

Como puedo llenar un treeview con el contenido de un archivo de texto??, el archivo de texto tiene la estructura siguiente:

Nivel 1
Subnivel 1
Subnivel 2
...........etc
Nivel 2
Subnivel 1
Subnivel 2
.........etc
Nivel 3
..........
..........

cada subnivel tiene un tab de espacio.

Gracias, espero y me ayuden.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ya!! pero porque no salen acentos???

Publicado por Treeview (8 intervenciones) el 18/07/2008 05:10:58
Esto es lo que encontre pero no salen los acentos cuando cargo el archivo en el treview!!! solo sale como un cuadrito., que le hace falta ???, ayudenme porfavor.
' Load a TreeView control from a file that uses tabs
' to show indentation.
Private Sub LoadTreeViewFromFile(ByVal file_name As String, _
ByVal trv As TreeView)
' Get the file's contents.
Dim stream_reader As New StreamReader(file_name)
Dim file_contents As String = stream_reader.ReadToEnd()
stream_reader.Close()

' Remove line feeds.
file_contents = file_contents.Replace(vbLf, "")

' Break the file into lines.
Const charCR As Char = CChar(vbCr)
Const charTab As Char = CChar(vbTab)
Dim lines() As String = file_contents.Split(charCR)

' Process the lines.
Dim text_line As String
Dim level As Integer
Dim tree_nodes() As TreeNode
Dim num_nodes As Integer = 0
ReDim tree_nodes(num_nodes)

trv.Nodes.Clear()
For i As Integer = 0 To lines.GetUpperBound(0)
text_line = lines(i)
If text_line.Trim().Length > 0 Then
' See how many tabs are at the start of the
' line.
level = text_line.Length - _
text_line.TrimStart(charTab).Length

' Make room for the new node.
If level > num_nodes Then
num_nodes = level
ReDim Preserve tree_nodes(num_nodes)
End If

' Add the new node.
If level = 0 Then
tree_nodes(level) = _
trv.Nodes.Add(text_line.Trim())
Else
tree_nodes(level) = tree_nodes(level - _
1).Nodes.Add(text_line.Trim())
End If
tree_nodes(level).EnsureVisible()
End If
Next i

If trv.Nodes.Count > 0 Then trv.Nodes(0).EnsureVisible()
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:ya!!

Publicado por treeview (8 intervenciones) el 18/07/2008 05:24:04
Solucionado..........
El archivo de texto tiene que ser en formato Unicode.

Bueno se los dejo haber si a alguien le sirve.

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar