Solved

Saving a treeview's structure

Posted on 1998-08-21
4
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

729 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