Solved

VB 6 Tree View Control

Posted on 2006-06-14
6
743 Views
Last Modified: 2012-08-13
I am using tree view control for displaying chart of account

My table structure is as follows:

Account_Code                  Account_Name


1      Assets
101         Office Premiesses


2      Equity & Liablitties

201      Share Capital

201001                              Authoriesed Capital
201002                              Paid Up Capital


and I am using following code on my form load

Private Sub Form_Load()
FrmMdi.Skin1.ApplySkin Me.hWnd
If RS.State = 1 Then RS.Close
RS.Open "SELECT * FROM AC_CHARTOFACC", cn, adOpenStatic, adLockOptimistic
Call PopulateTV
End Sub

Private Sub PopulateTV()
On Error Resume Next
TV.Style = tvwTreelinesPlusMinusPictureText
TV.LineStyle = tvwRootLines
Dim LevelOne As Node
Dim LevelTwo As Node
Dim LevelThree As Node
Dim LevelFour As Node
Dim LevelFive As Node
Dim LevelSix As Node

While RS.EOF = False
If IsNull(RS!level1) = False Then
'MsgBox RS!acc_name
Set LevelOne = TV.Nodes.Add(, , , RS!acc_name)
Set LevelTwo = TV.Nodes.Add(LevelOne, tvwChild, StrConv(LevelOne, vbProperCase), RS!acc_name)
End If
RS.MoveNext
Wend
End Sub

The above code is not showing acutal data as per hierarchy, please guide where i am doing mistake
0
Comment
Question by:Mehram
  • 3
  • 3
6 Comments
 
LVL 1

Expert Comment

by:kwebster7327
ID: 16913419
You probably need a more to get all the levels you want. If I understand your account structure, you need to query for the nodes in "tree" order, then parse the Acct_Code to determine when to create the child nodes. You'd continue on down the hierarchy until you ran out of sublevels.

Something like:

SELECT * FROM AC_CHARTOFAC ORDER BY Acct_Code

While RS.EOF = False
  Select Case Len(Acct_Code)
   case 1
     Set LevelOne = TV.Nodes.Add(, , CStr(RS!acc_code), RS!acc_name)
   case 3
     Set LevelTwo = TV.Nodes.Add(LevelOne, tvwChild, CStr(RS!acc_code), RS!acc_name)
   case 6
     Set LevelThree = TV.Nodes.Add(LevelTwo, tvwChild, CStr(RS!acc_code), RS!acc_name)
   case ...
  End Select
RS.MoveNext
Wend
0
 
LVL 1

Expert Comment

by:kwebster7327
ID: 16913955
After looking at it more, I realized I'm assuming the Acct_Code is text, not numeric. For numeric codes you'll have to use the code to figure out the key of the parent rather than assuming it's already known.

Something like:

SELECT * FROM AC_CHARTOFAC ORDER BY Acct_Code

While RS.EOF = False
  Select Acct_Code
   case 1 to 9
     Set LevelOne = TV.Nodes.Add(, , CStr(RS!acc_code), RS!acc_name)
   case 100 to 999
     LevelOne = TV.Nodes(CStr(Int(Acct_Code / 100)))
     Set LevelTwo = TV.Nodes.Add(LevelOne, tvwChild, CStr(RS!acc_code), RS!acc_name)
   case 100000 to 999999
     LevelTwo = TV.Nodes(CStr(Int(Acct_Code / 1000)))
     Set LevelThree = TV.Nodes.Add(LevelTwo, tvwChild, CStr(RS!acc_code), RS!acc_name)
   case ...
  End Select
RS.MoveNext
Wend
0
 

Author Comment

by:Mehram
ID: 16918680
Sir, i am checking and reverting
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Mehram
ID: 16918815
Sir, first of all yours provided info is excellent for me but it is not showing plus minus picture please guide me property setting
0
 

Author Comment

by:Mehram
ID: 16918820
I also want when user open this form the all account automatically shows according to hierarchy instead of that user use plus minus picture. please help
0
 
LVL 1

Accepted Solution

by:
kwebster7327 earned 500 total points
ID: 16919913
I always have to tinker with the style to get it to display right. I can't offer a better explanation than that without actually having all your code. Hint: Use the property window for the TV control and just try the values in the pulldowns for the style until you see the one you like best. Personally, I never set them in code because I always get them wrong when I do it that way. So, remove these lines:

   TV.Style = tvwTreelinesPlusMinusPictureText
   TV.LineStyle = tvwRootLines

and set the style through the property window instead.

As for showing the tree expanded, the node object has an "expanded" property. Set this to true as you create each node. Take a look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cmctl198/html/vbproexpandednode.asp.

You might also be interested in the "ensurevisible" method. That's what you'll use to get a specific node scrolled into view. It's at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cmctl198/html/vbmthensurevisible.asp.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scores100 challenge 3 84
wordsWithout 49 80
autoit - check if option is checked in another program 2 71
creating threads in delphi 1 55
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

746 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

9 Experts available now in Live!

Get 1:1 Help Now