Solved

VB 6 Tree View Control

Posted on 2006-06-14
6
762 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
Independent Software Vendors: 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

Technology Partners: 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!

Question has a verified solution.

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

This is about my first experience with programming Arduino.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

735 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