Link to home
Start Free TrialLog in
Avatar of thor918
thor918Flag for Norway

asked on

treeview ahhhhhh?

I need a sorting code that work like this:
I have two variable values X & Y. I need to get them listed in this order with the smallest value first in a treeview list. The Y Values must be sorted by the X values.

*************** Example  ***************

Treeview list:

X------+----Y
 |        |
 |         +----Y
 |        |
 |         +----Y
 |
 X-----+---Y
 |        |
 |        +---Y
 |        |
 |        +---Y
 |
 |
X-----+----Y
          |
         +---Y

Treeview list with values:

1------+----12
 |        |
 |         +----54
 |        |
 |         +----84
 |
 2-----+---1
 |        |
 |        +---2
 |        |
 |        +---3
 |
 |
3-----+----45
          |
         +---100

After this I need to put the values from the treeview to  two listbox'es
Like this:

         X                                          Y
  ************                     ************
  * Listbox1 *                    * Listbox1 *
  ************                     ************
 *       1         *                    *       12      *
 *       1         *                    *       54      *
 *       1         *                    *       84      *
 *       2         *                    *         1      *
 *       2         *                    *         2      *
 *       2         *                    *         3      *
 *       3         *                    *       45      *
 *       3         *                    *     100     *
 ************                      ************


It must be easy to add new X & Y values in the treeview list. And every time
new values are added they must be sorted in the same order. The small first.


Thanks
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

To get your treeview sorted, simply set the .Sorted Property of the treeview to True.
For your children, you need to change the .Sorted Property of your X nodes to true
To fill your Listboxes, simply do this:

DIM nodParent as Node
DIM nodChild as Node
SET nodParent = TreeView.Nodes.Root.FirstSibling

WHILE NOT( nodParent IS NOTHING )
  SET nodChild = nodParent.Child
  WHILE NOT (nodChild IS NOTHING)
    List1.Add nodParent.Text
    List2.Add nodChild.Text

    Set nodChild = nodCHild.Next
  WEND

  SET nodParent = nodParent.Next
WEND

Good luck
Avatar of thor918

ASKER

Adjusted points from 200 to 400
Avatar of thor918

ASKER

Nice. I going to try it at once!
Avatar of thor918

ASKER

I don't get the code you posted to work angelIII...
TreeView.Nodes.Root.FirstSibling
There's no  root under nodes
Avatar of thor918

ASKER

e-mail me at
thor918@postkassa.no
uups (this is because i typed the code directly here...) shame on me...

TreeView.Nodes(1).Root.FirstSibling

Avatar of thor918

ASKER

is someone want's to send me examples send it on my e-mail
Avatar of thor918

ASKER

okey. going to try it once more.
later...
Avatar of thor918

ASKER

okey. going to try it once more.
later...
Avatar of rbsubra
rbsubra

Hi,

First set the treeview.sorterd property true. Whenever adding a node, set that node.sorted=true. This will sort the values in a way u like. if ur having a numeric values to be sorterd prfix it blank spcces or zero for the length u want.

have any clarificatons get back to me....

okay!!!!!!!!!

sample code for ur reference......

Private Sub Form_Load()
Dim x As Node
Set x = TreeView1.Nodes.Add(, , , "4")
Call TreeView1.Nodes.Add(x.Index, tvwChild, , "0002")
Call TreeView1.Nodes.Add(x.Index, tvwChild, , "0003")
Call TreeView1.Nodes.Add(x.Index, tvwChild, , "0001")
Call TreeView1.Nodes.Add(x.Index, tvwChild, , "0010")
x.Sorted = True
Call TreeView1.Nodes.Add(, , , "1")
Call TreeView1.Nodes.Add(, , , "5")
TreeView1.Sorted = True
End Sub


I hope this will work out for u

Cheers
rbsubra
(*_*)
Avatar of thor918

ASKER

Thanks.
That worked.
But how do you add one value under the same X node. And how do you prevent that there is not more of the same value?

regards
Hey,

its so simple...........

have a look at this

Private Sub Form_Load()
AddNode 1, 2
AddNode 1, 3
AddNode 3, 1
AddNode 4, 1
End Sub

Private Function AddNode(x As String, y As String)
Dim nodeX As Node
Dim relNode As Node
If TreeView1.Nodes.Count > 0 Then
  Set nodeX = TreeView1.Nodes(1)
  Do While (nodeX Is Nothing) = False
    If nodeX.Text = x Then
      Set relNode = nodeX
      Set nodeX = Nothing
    Else
      Set nodeX = nodeX.Next
    End If
  Loop
End If
If relNode Is Nothing Then
  Set relNode = TreeView1.Nodes.Add(, , , x)
End If
Call TreeView1.Nodes.Add(relNode, tvwChild, , y)
TreeView1.Sorted = True
relNode.Sorted = True
End Function


ASKER CERTIFIED SOLUTION
Avatar of duboiss
duboiss

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial