Solved

Saving a treeview's structure

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add text to end of existing text in file 16 70
Macro: print each sheet to pdf using ExportAsFixedFormat 11 47
Saving history changes to sub form 4 42
Hide vba in gp 7 93
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

815 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

10 Experts available now in Live!

Get 1:1 Help Now