| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: Loading a treeview fr |
"Anthony Bopp" wrote in message
news:df6fb58d.0406180518.5cc42c03{at}posting.google.com...
> I'm trying to figure out an efficient way to represent a text file in
> a treeview control, but not being terribly experienced with either VB
> or treeviews, every solution I come up with seems waaay to complex and
> convoluted, and I'd appreciate any help in coming up with something
> simpler.
>
>
> Part of my difficulty is that the text file is "upside down" from the
> standpoint that what I want to be the parent nodes are actually at the
> bottom of the file. Another difficulty is that I'm sure there must be
> a relatively simple routine that can be used to populate all the
> nodes, but I just can figure out what that routine is.
>
> Help please?
Here is a stab at it. The parsing here is fairly primitive and assumes
things about the file structure that may or not always be true. But it
might give you some ideas. The treeview is named TV:
Option Explicit
Private Sub Command1_Click()
Dim nFile As Long
Dim nLen As Long
Dim sBuffer As String
Dim sLines() As String
'open the file
nFile = FreeFile
Open "C:\layerlist.txt" For Binary As nFile
'make a buffer and read the whole file in
nLen = LOF(nFile)
sBuffer = String(nLen, " ")
Get nFile, , sBuffer
Close nFile
'split the text into an array of lines
sLines = Split(sBuffer, vbNewLine)
'clear the treeview
TV.Nodes.Clear
'do the root level
Call DoLevel(sLines, "Layer []", "End Of File",
"layer", True)
'now do the next two levels
Call DoLevel(sLines, "NextLayer", "Layer []",
"sample", False)
Call DoLevel(sLines, "AnotherLayer", "NextLayer",
"test", False)
End Sub
Private Sub DoLevel(Lines() As String, Start As String, _
Finish As String, Tag As String, ByVal Root As Boolean)
Dim n As Long
Dim nPos As Long
Dim nPos2 As Long
Dim strName As String
Dim strParent As String
For n = LBound(Lines) To UBound(Lines)
If InStr(1, Lines(n), Finish & " ", vbTextCompare) > 0 Then
'end of level
strParent = ""
Else
nPos = InStr(1, Lines(n), Start & " ", vbTextCompare)
If Not Root And nPos > 0 Then
'found a start of this level
nPos = nPos + Len(Start & " ")
nPos2 = InStr(nPos, Lines(n), "[]", vbTextCompare)
'identify its parent
strParent = Mid(Lines(n), nPos, nPos2 - nPos)
ElseIf Root Or Len(strParent) > 0 Then
'have a parent, look for tag
nPos = InStr(1, Lines(n), Tag & "(", vbTextCompare)
If nPos > 0 Then
'have a tag, find content
nPos = nPos + Len(Tag & "(")
nPos2 = InStr(nPos, Lines(n), ")", vbTextCompare)
strName = Mid(Lines(n), nPos, nPos2 - nPos)
'make node as root or as child of parent
If Root Then
TV.Nodes.Add , , strName, strName
Else
TV.Nodes.Add strParent, tvwChild, _
strName, strName
End If
End If
End If
End If
Next n
End Sub
---
þ RIMEGate(tm)/RGXPost V1.14 at BBSWORLD * Info{at}bbsworld.com
---
* RIMEGate(tm)V10.2áÿ* RelayNet(tm) NNTP Gateway * MoonDog BBS
* RgateImp.MoonDog.BBS at 6/19/04 6:16:27 AM
* Origin: MoonDog BBS, Brooklyn,NY, 718 692-2498, 1:278/230 (1:278/230)SEEN-BY: 633/267 270 @PATH: 278/230 10/345 106/1 2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.