midavis
asked on
Sorting a Treeview
I have a Treeview on my form called vbData. I thought you could just set the Treeviews sorting property to true and it sorts everything alphabetically. Is this not true. I have my code below.
Set ActiveProject = gVBInstance.ActiveVBProjec t
tvData.Sorted = True
Set nNode = tvData.Nodes.Add()
nNode.Text = ActiveProject.Name
For Each cmp In ActiveProject.VBComponents
Set nNode = tvData.Nodes.Add(1, tvwChild)
iIndex = nNode.Index
nNode.Text = cmp.Name
Next
Set ActiveProject = gVBInstance.ActiveVBProjec
tvData.Sorted = True
Set nNode = tvData.Nodes.Add()
nNode.Text = ActiveProject.Name
For Each cmp In ActiveProject.VBComponents
Set nNode = tvData.Nodes.Add(1, tvwChild)
iIndex = nNode.Index
nNode.Text = cmp.Name
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Angel, this seemed to work, sort of. The last component I add to the tree does not get sorted. It stays on the top of the node it is supposed to be in.
Set ActiveProject = gVBInstance.ActiveVBProjec t
tvData.Sorted = True
Set nNode = tvData.Nodes.Add()
nNode.Text = ActiveProject.Name
' add the main nodes
For Counter = 1 To 6
Set nNode = tvData.Nodes.Add(1, tvwChild)
nNode.Text = mainNodes(Counter)
nNode.Sorted = True
Next
This is my updated code. The mainNodes array holds all the nodes whose parent is the root. All components I loop through are now added to one of these nodes. If I have three forms, "frmTest" "frmMain" "frmSimple", in the order they are in the projects, the sorting goes like this.
frmSimple
frmMain
frmTest
Any idea?
Set ActiveProject = gVBInstance.ActiveVBProjec
tvData.Sorted = True
Set nNode = tvData.Nodes.Add()
nNode.Text = ActiveProject.Name
' add the main nodes
For Counter = 1 To 6
Set nNode = tvData.Nodes.Add(1, tvwChild)
nNode.Text = mainNodes(Counter)
nNode.Sorted = True
Next
This is my updated code. The mainNodes array holds all the nodes whose parent is the root. All components I loop through are now added to one of these nodes. If I have three forms, "frmTest" "frmMain" "frmSimple", in the order they are in the projects, the sorting goes like this.
frmSimple
frmMain
frmTest
Any idea?
change
nNode.Sorted = True
into
nNode.Parent.Sorted = True
Cheers
nNode.Sorted = True
into
nNode.Parent.Sorted = True
Cheers
ASKER
The answer you sent me angel was pretty close. I had to manipulate it a bit, but I said I would give you some more points so here you go.
tvData.Sorted = True
Just after all noides were added?