Solved

Saving a treeview's structure

Posted on 1998-08-21
4
206 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

22 Experts available now in Live!

Get 1:1 Help Now