Solved

VB 6 Tree View Control

Posted on 2006-06-14
6
766 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

737 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