VB 6 Tree View Control

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
MehramAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
kwebster7327Connect With a Mentor Commented:
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
 
kwebster7327Commented:
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
 
kwebster7327Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
MehramAuthor Commented:
Sir, i am checking and reverting
0
 
MehramAuthor Commented:
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
 
MehramAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.