How can i load a treeview in visual basic 6

I have a visual basic 6 application and a table having staff names (surname, First Name and Middle Name )

I need to be able able to load the names sort alphabetically

The Nodes will be the alphabets  ( A, B ......... Z)
So every one whose surname starts with A will be listed together under Node A
But for all people under  Node 'A'  they will be listed sorted alphabetically

Same rule will apply for Nodes  'B'  to 'Z'

Has any body a clue what I should do.  Sample code if available will be very helpful

Thanks

Oluwole
Olukayode OluwoleSystems AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ManjuIT - Project ManagerCommented:
So lets say your Staffname table has Surname, etc. First write a query like

Select Left(Surname,1) as Label, Surname from Staffname order by Label.

This will be your query for your treeview control in vb6.

Use Label as your Parent node & Surname as child node
0
ManjuIT - Project ManagerCommented:
Example code using State & city from access. you can change the connection string & query.

        TreeViewList.Nodes.Clear()
        Connection = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & _
                                         "Data Source=world.accdb;Jet OLEDB:Database Password=xxxx;")
        Command = New OleDb.OleDbCommand("Select  * from Worldmap")
        Command.Connection = Connection
        Command.Connection.Open()


        '//RUN COMMAND
        DataReader = Command.ExecuteReader()
        Dim rows As Integer = 0


        While DataReader.Read()
            Dim columns As Integer


            TreeViewList.Nodes.Add(DataReader(1).ToString())
            For columns = 1 To 2
                TreeViewList.Nodes(rows).Nodes.Add(DataReader.Item(2).ToString())
            Next


            rows += 1
        End While

Open in new window

0
Olukayode OluwoleSystems AnalystAuthor Commented:
Thank you Manju,
I noticed you used Datareader control which is not in my project
I attch an page . Command4  button has the code below,  The white portion is the Treeview
Control added as TreeviewList

Initially I used the Outline Control ( from VB4 ) and I am just trying to
replace  the outline control with the TreeView Control

Below is code  from outline which I am now modifying for TreeView

TreeViewList.Nodes.Clear
 Set ADOprimaryrs2 = New Recordset
    '-----------------------------------------------
  ADOprimaryrs2.Open "select staff_no,surname,firname,midinit  " & _
                      " from empltab ", db, adOpenStatic, adLockOptimistic


 
  TreeViewList.Nodes.Clear
 
  'Fill top level A-Z
  For i = 0 To 25
      TreeViewList.Nodes.Add Chr$(65 + i)
      'Outline1.AddItem Chr$(65 + i)
      'Outline1.Indent(Outline1.ListCount - 1) = 1

      'Add Names
      Do While Not ADOprimaryrs2.EOF
            If UCase(Left(ADOprimaryrs2!surname, 1)) = Chr$(65 + i) Then
              TreeViewList.Nodes.Add ADOprimaryrs2!surname + ", " + ADOprimaryrs2!firname + ";     " + ADOprimaryrs2!staff_no
              'Outline1.Indent(Outline1.ListCount - 1) = 2
              ADOprimaryrs2.MoveNext
            Else
              Exit Do
            End If
      Loop
  Next i

I used Chr$(65 + i)  to generate 'A'  to 'Z'
and the IF  statement simply  tries see what the  first character  of the surname is  so
it knows which node to attach it to

I believe the syntax of the treeview control is where the problem is

I attach a screen print of the debugger to let you where the error occured

Whats the correct syntax for this Line

Thanks
TreeListError.PNG
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Olukayode OluwoleSystems AnalystAuthor Commented:
I am sorry I missed out this second attachment that shows
the first error line

Regards

Oluwole
TreeListErrorScreen2.PNG
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Olukayode OluwoleSystems AnalystAuthor Commented:
Thanks for the guide.

I downloaded the sample and ran it as is ( ie vb against an access Database ) and it ran

I import the form into my project and converted the Db into  sqlserver

On runing i got an error  ( see attached code with the line debugged  )

What imagelist am i to initialize

Thanks

Oluwole
TreeViewError-26-01-2018.docx
0
Olukayode OluwoleSystems AnalystAuthor Commented:
Thanks for the effort. I am still battling with getting my nodes to be 'A'  to 'Z' but at least I got the treview working now
Oluwole
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.