|
-
Nov 2nd, 2005, 10:38 PM
#1
Thread Starter
Frenzied Member
add a button while running and how u use a treeview
ok i got 2 questions... how do u add a button while the program is running, like for example u hit a button and it creates another 1.
second how do u use a treeview i wanna do this.
add a node then a node in the node so it looks like
we
|
-we2
+we3
so when we is opened it shows we2
-
Nov 2nd, 2005, 10:50 PM
#2
Re: add a button while running and how u use a treeview
-
Nov 3rd, 2005, 07:21 AM
#3
Thread Starter
Frenzied Member
Re: add a button while running and how u use a treeview
can u plz simplify the treeview one
-
Nov 3rd, 2005, 08:11 AM
#4
Re: add a button while running and how u use a treeview
-
Nov 3rd, 2005, 08:17 AM
#5
Re: add a button while running and how u use a treeview
The simple fact is that the TreeView itself and every node in the TreeView has a Nodes property. If you want to add a node to the TreeView you call:
VB Code:
myTreeView.Nodes.Add(newTreeNode)
If you want to add a node to an existing node you would call:
VB Code:
myTreeNode.Nodes.Add(newTreeNode)
If you wanted to add a node to the first node in the TreeView you could do it like this:
VB Code:
myTreeView.Nodes(0).Nodes.Add(newTreeNode)
-
Nov 6th, 2005, 09:09 PM
#6
Thread Starter
Frenzied Member
Re: add a button while running and how u use a treeview
 Originally Posted by jmcilhinney
The simple fact is that the TreeView itself and every node in the TreeView has a Nodes property. If you want to add a node to the TreeView you call:
VB Code:
myTreeView.Nodes.Add(newTreeNode)
If you want to add a node to an existing node you would call:
VB Code:
myTreeNode.Nodes.Add(newTreeNode)
If you wanted to add a node to the first node in the TreeView you could do it like this:
VB Code:
myTreeView.Nodes(0).Nodes.Add(newTreeNode)
im trying to use this code
VB Code:
Dim ty2 As Long
For ty2 = 0 To ListBox1.Items.Count - 1
If ListBox1.Items.Item(ty2) = we Then
TreeView1.Nodes(ty2).Nodes.Add(temp2)
End If
Next ty2
but it has an error on TreeView1.Nodes(ty2).Nodes.Add(temp2)
its fine if i do something like TreeView1.Nodes(0).Nodes.Add(temp2)
-
Nov 6th, 2005, 09:35 PM
#7
Re: add a button while running and how u use a treeview
If you read my signature you'll see that in my book "an error" doesn't cut it.
-
Nov 6th, 2005, 10:07 PM
#8
Thread Starter
Frenzied Member
Re: add a button while running and how u use a treeview
 Originally Posted by jmcilhinney
If you read my signature you'll see that in my book "an error" doesn't cut it.
does this help?
Error 1 Overload resolution failed because no accessible 'Item' can be called without a narrowing conversion:
'Public Overridable ReadOnly Default Property Item(key As String) As System.Windows.Forms.TreeNode': Argument matching parameter 'key' narrows from 'Long' to 'String'.
'Public Overridable Default Property Item(index As Integer) As System.Windows.Forms.TreeNode': Argument matching parameter 'index' narrows from 'Long' to 'Integer'. C:\Documents and Settings\*****\Desktop\vb.net projects\tag viewer2\Form1.vb 132 25 tag viewer
-
Nov 6th, 2005, 10:36 PM
#9
Re: add a button while running and how u use a treeview
You should turn Option Strict On and then that code wouldn't even compile. It would give you a compile error telling you that you could not implicitly convert from a Long to an Integer. Is there a particular reason that you have chosen to use a Long? You index pretty much every collection with an Integer, and using the Integer type is more efficient than using a Long in general. Are you planning on having more than 2,147,483,648 nodes in your TreeView? 
With regards to Option Strict, it disallows late binding and implicit narrowing conversions, as you tried to make here. It will help catch many potential issues at design time rather than run time, which makes your code more robust. EVERY VB.NET developer should have it turned On ALWAYS.
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
|