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
Re: add a button while running and how u use a treeview
Re: add a button while running and how u use a treeview
can u plz simplify the treeview one
Re: add a button while running and how u use a treeview
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)
Re: add a button while running and how u use a treeview
Quote:
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)
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.
Re: add a button while running and how u use a treeview
Quote:
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
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.