Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello

 

I currently have the following code to retrive records from a Dataset and populate the treeview. I would like to now place child nodes under each parent, from a different dataset where the seasons are equal (you'll see what i mean in the code). I'm really stuck as to how to do this:

 

Current Code:

 

'Populate Treeview

Dim varTVItem As TreeNode

Dim varDSRow As DataRow

 

tvSeasons.Nodes.Clear()

dsSeasonData = DsSeasons1

For Each varDSRow In dsSeasonData.Tables("seasons").Rows

 

varTVItem = New TreeNode()

 

With varTVItem

.Text = varDSRow.Item("Season")

End With

tvSeasons.Nodes.Add(varTVItem)

Next

 

Thanks in advance

Visit: VBSourceSeek - The VB.NET sourcecode library

 

 

"A mere friend will agree with you, but a real friend will argue."
  • *Experts*
Posted

Each time you call Add, it returns the node that was added. Using that node, you can add children easily. As divil said, your DataSet may be structured to make things easier (or even recursive), but here's a sample to show how to add 3 parent nodes. Each parent node will have 2 children.

 

// Add a parent node
TreeNode node = treeView1.Nodes.Add("hello 1");
// Add two children.
// This works because both children use "node" as the parent
// to add to. The "node" variable is not reset
// til farther down.
node.Nodes.Add("child 1");
node.Nodes.Add("child 2");

// Here, node is reset to be the *next*
// parent node. It's a parent because it's
// added directly to the treeView1 control
node = treeView1.Nodes.Add("hello 2");
node.Nodes.Add("child 1");
node.Nodes.Add("child 2");

node = treeView1.Nodes.Add("hello 3");
node.Nodes.Add("child 1");
node.Nodes.Add("child 2");

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...