treeView child with own listView and rtb

Gamezhoek

Member
Joined
Jan 13, 2006
Messages
9
Programming Experience
1-3
I made a treeView, and I did that you can create your own roots and childs. I used this code to let you create your own child:
VB.NET:
If Not textBox1.Text = "" Then
            Treeview1.SelectedNode.Nodes.Add(textBox1.Text)
            textBox1.Text = ""
        ElseIf textBox1.Text = "" Then
            System.Windows.Forms.MessageBox.Show("You didn't gave the child a name.")
        End If
So, the child gets the name of the text in textBox1.
This is on the left side of the form.
On the right side, there is a richTextBox and a listView. How can I do that every child gets his own richTextBox and his own listView, with their own text.
So if I create million diffrent childs, there are million diffrent richTextBoxes and listViews.
 
You would be better of using only one of each control but populating them with different data depending on the selected node. As an example, when you are using Windows Explorer, do you think that each folder in the tree on the left has its own ListView control on the right? No, it doesn't. The single ListView is simply repopulated each time a different node is selected. Normally you would just retrieve the data for a node the first time that node is selected, then cache it in case that node is selected again later. You could use a keyed collection as the cache, like a Hashtable, where the TreeNode is the key and the data is the value. Then, when a node is selected, you would do something like this:
VB.NET:
Dim data As Object = dataCollection(selectedNode)

If data Is Nothing Then
    'The collection does not contain data for this node so retrieve it.
    data = GetData(selectedNode)

    'Cache the data for next time.
    dataCollection.Add(selectedNode, data)
End If

'Populate ListView or RichTextBox or whatever using data here.
 
Gamezhoek said:
The code doesn't work. It says that it doesn't know what GetData is. And it give's many more errors.
Of course it doesn't. That is just any old method that gets the data you want. That code is just an example of how you would do it. It's up to you to implement it such that it does what you want. I'm not here to spoon feed anyone. I've provided the principle but it's up to you to provide the implementation.
 
Back
Top