• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 84
  • Last Modified:

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
0
Olukay
Asked:
Olukay
  • 4
  • 3
1 Solution
 
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
 
OlukaySystems 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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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

Regards

Oluwole
TreeListErrorScreen2.PNG
0
 
OlukaySystems 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
 
OlukaySystems 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
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.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now