Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21136

up and down a tree

$
0
0
ok two questions in one go :)

to move an item up a treeview im using this

Code:

Private Sub Cmdup_Click()
Dim I As Integer
Dim strTemp1 As String
Dim strTemp2 As String
Dim strTemp3 As String
For I = 1 To treeUsers.Nodes.Count - 1 '
If treeUsers.Nodes.Item(I + 1).Index < "0" Then Exit Sub
If treeUsers.Nodes.Item(I + 1) = itemtobemoved.Text Then
strTemp1 = treeUsers.Nodes.Item(I + 1)
strTemp2 = treeUsers.Nodes.Item(I)
strTemp3 = strTemp1
strTemp1 = strTemp2
strTemp2 = strTemp3
treeUsers.Nodes.Item(I + 1).Text = strTemp1
treeUsers.Nodes.Item(I).Text = strTemp2
Exit Sub
End If
Next
End Sub

and to move it down a treeview im using

Code:

Private Sub Cmddwn_Click()
Dim I As Integer
Dim strTemp1 As String
Dim strTemp2 As String
Dim strTemp3 As String
For I = 0 To treeUsers.Nodes.Count - 1  '
If treeUsers.Nodes.Item(I + 1).Index > treeUsers.Nodes.Count - 1 Then Exit Sub
If treeUsers.Nodes.Item(I + 1) = itemtobemoved.Text Then
strTemp1 = treeUsers.Nodes.Item(I + 2)
strTemp2 = treeUsers.Nodes.Item(I + 1)
strTemp3 = strTemp1
strTemp1 = strTemp2
strTemp2 = strTemp3
treeUsers.Nodes.Item(I + 2).Text = strTemp1
treeUsers.Nodes.Item(I + 1).Text = strTemp2
Exit Sub
End If
Next
End Sub

is there any improvements on the code anyone can point out although it seems to work ok

Second Q

i want to move an item to the forth position of treeview

store the 4th item , 5th , 6th what evers left of the treeview and replace it all in order as it was
but i cant see an easy way to do so

any help thanks : )

Code:

Private Sub mvefourth_Click()
Dim T As Integer
Dim I As Integer
Dim strTemp1 As String
Dim strTemp2 As String
Dim strTemp3 As String
Dim strTempleft(0 To 9000) As String
For I = 1 To treeUsers.Nodes.Count - 1 '
strTemp1 = treeUsers.Nodes.Item(4)

For T = 4 To treeUsers.Nodes.Count - 1
strTempleft(T) = treeUsers.Nodes.Item(T)
Next T
Next I

treeUsers.Nodes.Item(4).Text = itemtobemoved.Text

End Sub


Viewing all articles
Browse latest Browse all 21136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>