|
-
Oct 7th, 2007, 08:13 AM
#1
Thread Starter
Hyperactive Member
basic treeview
hi all
im putting together a treeview of my video collection. and im wanting to add all the information about the video under the title. can anyone help
i have never used treeview before i normaly use listview.
i have manged to add the titles using the code below
--
im wanting to add under the title a tree 3 deep, so that i can add all the info of the video
Code:
Dim I As Integer ' Declare a counter variable.
For I = 1 To 4
Set nodX = TreeView1.Nodes.Add(, , , "title-- " & CStr(I))'this is out of msdn help
Next I
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
Oct 7th, 2007, 09:09 AM
#2
Re: basic treeview
Here is a sample I threw together quickly if you have any questions just ask:
Code:
Private Sub Command1_Click()
Dim tvwItem As MSComctlLib.Node
Dim a As Long, b As Long
With TreeView1
.Appearance = cc3D
.LineStyle = tvwTreeLines
With .Nodes
Set tvwItem = .Add(, , "Root", "Root")
For a = 1 To 10
Set tvwItem = .Add("Root", tvwChild, "Item " & a, "Item " & a)
For b = 1 To 5
Set tvwItem = .Add("Item " & a, tvwChild, a & "SubItem " & b, "SubItem " & b)
Next b
Next a
End With
For Each tvwItem In .Nodes
tvwItem.Expanded = True
Next
.Nodes.Item("Root").Selected = True
End With
Set tvwItem = Nothing
End Sub
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Oct 7th, 2007, 10:18 AM
#3
Re: basic treeview
A little more detial:
vb Code:
Private Sub Command1_Click()
Dim tvwItem As MSComctlLib.Node, tvwSubItem As MSComctlLib.Node
Dim a As Long, b As Long
With TreeView1
.Appearance = cc3D
.Checkboxes = True
.LineStyle = tvwTreeLines
With .Nodes
Set tvwItem = .Add(, , "Root")
tvwItem.Text = "Root"
tvwItem.Tag = "Expand"
For a = 1 To 10
Set tvwItem = .Add("Root", tvwChild, "Item " & a)
tvwItem.Text = "Item " & a
tvwItem.Bold = (a Mod 3)
tvwItem.Checked = (a Mod 2)
' tvwItem.Image = "ImageName" ' If you have an Image Box
tvwItem.ForeColor = (25 * a)
tvwItem.Tag = "Expand"
For b = 1 To 5
Set tvwSubItem = .Add(tvwItem.Key, tvwChild, a & "SubItem " & b)
tvwSubItem.Text = "SubItem " & b
Next b
Next a
End With
For Each tvwItem In .Nodes
tvwItem.Expanded = (tvwItem.Text = "Root") ' Will expand all children root nodes
Next
.Nodes.Item("Root").Selected = True ' Will ensure that root node is visible
End With
Set tvwItem = Nothing
Set tvwSubItem = Nothing
End Sub
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Oct 7th, 2007, 04:30 PM
#4
Thread Starter
Hyperactive Member
Re: basic treeview
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
Oct 8th, 2007, 06:23 AM
#5
Re: basic treeview
I have to used two methods HitTest and SelectedItem, but I prefer HitTest to find the selected item:
HitTest Method
vb Code:
Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim tvwItem As MSComctlLib.Node
Set tvwItem = TreeView1.HitTest(x, y)
If Not (tvwItem Is Nothing) Then Label1.Caption = tvwItem.Text
Set tvwItem = Nothing
End Sub
or SelectedItem Method
vb Code:
Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim tvwItem As MSComctlLib.Node
Set tvwItem = TreeView1.SelectedItem
If Not (tvwItem Is Nothing) Then Label1.Caption = tvwItem.Text
Set tvwItem = Nothing
End Sub
Last edited by Mark Gambo; Oct 8th, 2007 at 06:27 AM.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Oct 8th, 2007, 06:30 AM
#6
Re: basic treeview
IMO you should focus on how you store the data (and subsequent different retrieval criteria) before worrying too much of the interface; function over form. Are you already using a database (and using primary keys), or storing the info as XML (again with unique IDs)?
-
Oct 8th, 2007, 06:34 AM
#7
Re: basic treeview
Another trick you can use is simulating a ToolTip Text for each node. If you check you will see that the individual nodes don't have a ToolTipText property, when loading the nodes set it ToolTipText to what ever you want it to be in its Tag Property:
vb Code:
tvwSubItem.Tag = "ToolTip Text Here"
and then use the following code:
vb Code:
Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim tvwItem As MSComctlLib.Node
Set tvwItem = TreeView1.HitTest(x, y)
If Not (tvwItem Is Nothing) Then TreeView1.ToolTipText = tvwItem.Tag
Set tvwItem = Nothing
End Sub
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Oct 8th, 2007, 06:37 AM
#8
Re: basic treeview
 Originally Posted by leinad31
IMO you should focus on how you store the data (and subsequent different retrieval criteria) before worrying too much of the interface; function over form. . . .
Most times you are correct, but I have designed applications where I had to design the front end first then the backend due to the customer's constant requests for new features and functions. Don't worry they paid handsomely for those changes
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Oct 8th, 2007, 06:41 AM
#9
Re: basic treeview
Here is the complete code with the ToolTextTips with Parent, Child, GrandChild and Great GrandChild nodes:
vb Code:
Option Explicit
Private Sub Command1_Click()
Dim tvwItem As MSComctlLib.Node, tvwSubItem As MSComctlLib.Node
Dim tvwSubSubItem As MSComctlLib.Node
Dim a As Long, b As Long, c As Long
With TreeView1
.Appearance = cc3D
.Checkboxes = True
.LineStyle = tvwTreeLines
With .Nodes
Set tvwItem = .Add(, , "Root")
tvwItem.Text = "Parent"
tvwItem.Tag = "Root"
For a = 1 To 10
Set tvwItem = .Add("Root", tvwChild, "Item " & a)
tvwItem.Text = "Child " & a
tvwItem.Bold = (a Mod 3)
tvwItem.Checked = (a Mod 2)
tvwItem.ForeColor = (25 * a)
tvwItem.Tag = "ToolTip Text - " & tvwItem.Text
For b = 1 To 5
Set tvwSubItem = .Add(tvwItem.Key, tvwChild, a & "SubItem " & b)
tvwSubItem.Text = "GrandChild " & b
tvwSubItem.Tag = "ToolTip Text - " & tvwSubItem.Text
If b Mod 3 Then
For c = 1 To 3
Set tvwSubSubItem = .Add(tvwSubItem.Key, tvwChild, a & "SubSubItem " & b & "-" & c)
tvwSubSubItem.Text = "Great GrandChild " & c
tvwSubSubItem.Tag = "ToolTip Text - " & tvwSubSubItem.Text
Next c
End If
Next b
Next a
End With
For Each tvwItem In .Nodes
tvwItem.Expanded = (tvwItem.Key = "Root") ' Will expand all children root nodes
Next
.Nodes.Item("Root").Selected = True ' Will ensure that root node is visible
End With
Set tvwItem = Nothing
Set tvwSubItem = Nothing
Set tvwSubSubItem = Nothing
End Sub
Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim tvwItem As MSComctlLib.Node
Set tvwItem = TreeView1.HitTest(x, y)
If Not (tvwItem Is Nothing) Then TreeView1.ToolTipText = tvwItem.Tag
Set tvwItem = Nothing
End Sub
Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim tvwItem As MSComctlLib.Node
Set tvwItem = TreeView1.SelectedItem
If Not (tvwItem Is Nothing) Then Label1.Caption = tvwItem.Text
Set tvwItem = Nothing
End Sub
Last edited by Mark Gambo; Oct 8th, 2007 at 06:48 AM.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|