Solved

VB 6 Tree View Control

Posted on 2006-06-14
6
754 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Report events not being triggered 8 120
split53 challenge 7 95
How to remove numeric and alpha from an alphanumeric field? 5 85
Cygwin - GNU GPL License 1 23
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

786 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