Solved

Saving a treeview's structure

Posted on 1998-08-21
4
205 Views
Last Modified: 2010-04-30
Hello I have a treeview on a form.  This treeview control is created by the user to show the structure of a specific system.  What I need is a way to save the structure of the treeview control between session.  I'm really not sure how to go about this so if anyone has any idea on how to create this structure in a database.

If you can give me full source on how to do this.  Basically I'm looking for two function SaveSystem and LoadSystem.  If you provide these function I'll triple the points.
 
0
Comment
Question by:PCav
  • 2
4 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1430332
How complicated the tree  control is:
1. Is there a need in saving image info
2. How many levels
3. Is it text only, or also keys
4. How big it in general
0
 

Author Comment

by:PCav
ID: 1430333
Question one image info needed.

Question two realistically 3 or 4 levels, but could possible be larger.

It needs to save text, plus 2 other pieces of information (one is in the tag of the node and the other depends on the type of icon the person used (there are only less than 10 icons that won't ever change)

General size less than 100 entries all together in most cases, but again could be larger.
0
 
LVL 6

Accepted Solution

by:
anthonyc earned 50 total points
ID: 1430334
Assuming that the imagelist has all the icons you need in it, then you can do this.. by saving to the registry (this can be adjusted to save to an INI file, which I think is better)

public sub SaveTreeview(tvw as treeview)
  dim nodCur as node
  dim szVal  as string

  for each nodCur in tvw.nodes
     savesetting app.exename, tvw.name & "_Node" & nodcur.index & "_Key", nodcur.key
     savesetting app.exename, tvw.name & "_Node" & nodCur.index & "_Text", nodCur.text
     SaveSetting app.exename, tvw.name & "_Node" & nodcur.index & "_Icon", nodCur.image
     SaveSetting app.exename, tvw.name & "_Node" & nodcur.index & "_Index" & nodCur.index

     if not nodcur.parent is nothing then
        savesetting app.exename, tvw.name & "_Node" & nodcur.index & "_Parent" & iif(nodcur.key = "", nodcur.index, nodcur.key)
     end if
  next nodcur
end sub

public sub LoadTreeview(tvw as treeview)
  dim nodCur as node
  dim nIndex as integer
  dim szVal  as string
  dim szkey  as string
  dim szIcon as string
  dim szPar  as string

  tvw.nodes.clear

  nIndex = getsetting(app.exename, tvw.name & "_Node1_Index", 0)
  do until nIndex = 0
    szKey = getsetting(app.exename, tvw.name & "_Node" & nIndex & "_Key", "")
    szVal = getsetting(app.exename, tvw.name & "_Node" & nIndex & "_Text", "")
    szIcon = getsetting(app.exename, tvw.name & "_Node" & nIndex & "_Icon", "")
    szPar = getsetting(app.exename, tvw.name & "_Node" & nIndex & "_Parent", "")

    if len(szPar) > 0 then
      set nodCur = tvw.nodes.add(iif(isNumeric(szPar), clng(szPar), szPar), tvwchild, szkey, szval, szicon, szicon)
    else
      set nodCur = tvw.nodes.add(,, szkey, szval, szicon, szicon)
    end if

    nIndex = getsetting(app.exename, tvw.name & "_Node" & (nIndex + 1) & "_Index", 0)
  loop
end sub
0
 

Author Comment

by:PCav
ID: 1430335
Thank You for your help I don't think I'm gonna use your code.  I gonna save the Treeview control in and XML document.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now