ASP.net Treeview with child node on childnode - asp.net

I have been given a dataset to work with that is layed out in the format of
Object | Type | Level | Comments | Parent | Child
So far I have been able to get the Object as the Parent Node and the Comments as a child node, however I need to get multiple children for this parent, and then children on them
An example of what I mean is like so
Object | Type | Level | Comments | Parent | Child
Dave | WH | 1 | comment | root | null
Simon | WH | 1 | comment | root | Fortnum
Simon | WH | 1 | comment | root | Mason
Tim | WH | 1 | comment | root | null
wallace| WH | 2 | comment | Simon | null
Mason | WH | 2 | comment | Simon | Mouse
Mouse | WH | 3 | comment | Mason | null
I need it to look like this
I have looked at the code from here Similar Stack Answer but its not working for me
I am pulling the sql data into a datatable and then looping through it to try and build the tree view.
This is the code that I am using that is only giving me the object as a parent node, and then the comment as a child node, but I need to be able to locate the actual children of the and then add them to the treeview.
For Each row As DataRow In dt.Rows
node = Searchnode(row.Item(4).ToString(), TreeView1)
If node IsNot Nothing Then
subNode = New TreeNode(row.Item(3).ToString())
node.ChildNodes.Add(subNode)
Else
node = New TreeNode(row.Item(0).ToString())
subNode = New TreeNode(row.Item(3).ToString())
node.ChildNodes.Add(subNode)
TreeView1.Nodes.Add(node)
End If
Next
then the function
Private Function Searchnode(ByVal nodetext As String, ByVal trv As TreeView) As TreeNode
For Each node As TreeNode In trv.Nodes
If node.Text = nodetext Then
Return node
End If
Next
End Function
Ive never really worked with treeviews before in ASP.Net but would be very grateful if anyone can help me.

Its not necessary to add child nodes when you add a new node. If the datatable is sorted the way your example shows the childnode will come up with a reference to its parent after the parent has already been added to the treeview.
so prior to this example edit the datatable and remove the duplicate objects
like remove one of the simons. the(child) column is not needed. also (optionally) going to add a reference to the parent when adding the child.
For Each row As DataRow In dt.Rows
node = Searchnode(row.Item(4).ToString(), TreeView1.Nodes)
If node IsNot Nothing Then
subNode = New TreeNode(row.Item(0).ToString()){ parent= node }
node.Nodes.Add(subNode)
Else 'root node
node = New TreeNode(row.Item(0).ToString())
TreeView1.Nodes.Add(node)
End If
Next
also searchnode needs to be recursive to check child nodes.
Private Function Searchnode(ByVal nodetext As String, ByVal tn As TreeNodeCollection) As TreeNode
TreeNode ret = nothing
For Each node As TreeNode In tn.Nodes
If node.Text = nodetext Then
ret = node
exit for
Else
ret = Searchnode(nodetext, node.Nodes)
End If
Next
Return ret
End Function

Related

How to get the value of imageview in tilepane, JavaFX?

I made a tilepane in JavaFX. And I put some imageview on tilepane.
tilepane => imageview => image
I want to get the value of image in imageview in tilepane(first row, first column).
this value
↓
| 0,0 | 0,1 | 0,2 | 0,3 | 0,4 |
| 1,0 | 1,1 | 1,2 | 1,3 | 1,4 |
I tried to
System.out.println(tilepane.getChildren().get(0))
=> result : Pane#2fc42278
I can access to tilepane(first row, first column).
But I can't get the inner value. My final goal is getting the image's name.
How can I get the value of image?
Thanks in advance!
A Node has a method setUserData into which you can put any object. You could assign the ImageView object a name via the setUserData method.
Iterating through the TitledPane would be like this:
TitledPane pane = ...
for( Node child: pane.getChildrenUnmodifiable()) {
if( child instanceof ImageView) {
ImageView imageView = (ImageView) child;
System.out.println( imageView.getUserData());
}
}
That way you check for ImageView. But of course you could as well check the userData of all nodes without checking for ImageView.

AngularFire: how to set only a property?

Just beginning with firebase... :-(
How do I set a property of an item?
This is my data structure:
myproject
|
- players
|
- -JPUAYuKUNeevXxaCMxM
|
- name: "John"
|
- skill
|
- mu: 25
|
- sigma: 8.333
- -JPUAYuRyJBH8sF93pNt
...
I can add a player with:
var ref = new Firebase(FIREBASE_URL + '/' + 'players');
ref.child(id).set(player);
The question is: how do I update only one property of an item (for example, 'skill') ?
I did try with:
var skill = {};
skill.mu = 27.0;
skill.sigma = 7.0;
ref.child(id).skill.update(skill);
I think I know what's going on here.
You expected ref.child(id) to have a property skill. However, you actually want the "skill" child; ref.child(id).child("skill").

Populating tree in flex using array

Hi my required tree structure is as follows
a -- b -- d
| |
| |
| -- e
-- c
I have my string array as follows
a/b,c
b/d,e
d/
e
where the component before / represents parent and the children of the corresponding parent are separated by ,
Can anyone provide me the logic to create a array collection for this hierarchy to set as dataprovider to my tree.
Thanks and regards
Here's the general idea. (I'm not going to type all of the nodes out) Another approach is to create an object that has label and children properties rather than creating all of this dynamically with Objects. Hope that helps.
var dp:Array = new Array();
dp[0] = new Object();
dp[0].label = "a";
dp[0].children = new Array();
dp[0].children[0] = new Object();
dp[0].children[0].label = "b";
myTree.dataProvider = dp;

Tree structure category sum that cascades to root node

I'm going to come right out and say that I am not the worlds greatest Mathematician :D So this problem may well be simple to most of you. Unfortunately it's confusing me and have had several stabs at a workable solutions.
As with any tree, one can have many branches, many branches can have more branches and so forth until they end with a leaf node. I've got information on each leaf that indicates its value.
What I require is a clear explination on how to tackle the problem of summarising each leaf node value as a total for it's branch (parent) and doing the same for the rest but not forgetting that if a branch is shared by other branches that it is the summary of each lower level branch and leaf that is directly related to itself.
To better explain:
Root
|----Branch
| |-Leaf 10
|----Branch
| |----Branch
| |-Leaf 20 |-Leaf 30
|----Branch |-Leaf 40
| |----Branch
| |----Branch
| |----Leaf 50
|-Leaf 60
The goal:
Root 210
|----Branch 10
| |-Leaf 10
|----Branch 90
| |----Branch 70
| |-Leaf 20 |-Leaf 30
|----Branch 50 |-Leaf 40
| |----Branch 50
| |----Branch 50
| |----Leaf 50
|-Leaf 60
I am able to identify the lowest level members (leaf nodes), the root node and the branches themselves. I don't have identification on whether or not the branch has other branches linked to itself lower down or directly linked to a leaf node. The relationship is very much bottom upwards to root. IE: The branch has no reference to who it's children are, but the children know who the parent is.
Please if something is unclear ask and I'll try and explain the problem better.
Any help would be appreciated.
OK, lefts give this a stab.
I would go about it like this with some pseudo code
foreach leaf in knownLeafs
parent = leaf.parent //get the leaf parent
parent.total = parent.total + leaf.value //add leaf value to parent total
while parent.parent != null //loop until no more parents, this would be the root
{
current = parent
parent = parent.parent //move up the structure
parent.total = parent.total + current.total
}
next leaf
you would need to create a function that will, given a node, return the parent node
node GetParentNodeFrom(node)
the new pseudo code would look something like this
foreach leaf in knownLeafs
parent = GetParentNodeFrom(leaf) //get the leaf parent
parent.total = parent.total + leaf.value //add leaf value to parent total
while GetParentNodeFrom(parent) != null //loop until no more parents, this would be the root
{
current = parent
parent = GetParentNodeFrom(current) //move up the structure
parent.total = parent.total + current.total
}
next leaf
Sorry, my mistake, you should only move the leaf value up, not the totals too.
See new leafValue used.
foreach leaf in knownLeafs
parent = GetParentNodeFrom(leaf) //get the leaf parent
leafValue = leaf.value
parent.total = parent.total + leafValue //add leaf value to parent total
while GetParentNodeFrom(parent) != null //loop until no more parents, this would be the root
{
current = parent
parent = GetParentNodeFrom(current) //move up the structure
parent.total = parent.total + leafValue
}
next leaf
You want to determine the sum of all the nodes in the tree?
Tree walking lends itself to an elegant recursive solution:
public int SumTree (TreeNode n) {
if(n.isLeafNode) return n.value;
return SumTree(n.left) + SumTree(n.right);
}
Assuming a binary tree.

Making a specific node expand based on the navigate URLs of its children

So I have a TreeView and it has about 7 parent nodes that have 3-5 children each. All of these children nodes when click navigate to a URL. What I would like to do is have one parent node auto-expand based on the URL and the other parent nodes to collapse.
If that wasn't clear, here is an example:
Root
|
|--Admin
| |
| |--Add.aspx
| |--Delete.aspx
|
|
|
|--Purchases
|
|--Orders.aspx
|--Stock.aspx
Lets say the user clicked on Orders.aspx, this would navigate them to that page, and when it does, I would want the tree view to collapse all parent nodes, and expand the current parent node. So Admin would be collapsed and Purchases would be expanded.
What I've attempted so far is this:
Protected Sub resize(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.Load
For Each node As TreeNode In (CType(sender, TreeView)).Nodes
If node.NavigateUrl = GetCurrentPage() Then
For Each parentN As TreeNode In (CType(sender, TreeView)).Nodes
If Not (parentN.Parent.Selected = True And node.Parent.Text = parentN.Parent.Text) Then
parentN.Collapse()
Else : parentN.Expand()
End If
Next
End If
Next
End Sub
Public Shared Function GetCurrentPage() As String
Return System.IO.Path.GetFileName(HttpContext.Current.Request.Url.AbsolutePath).ToLower
End Function
I'm not really sure how to go about this.
Unless your tree is more complicated than you're describing, why won't this loop work?
For Each node As TreeNode In (CType(sender, TreeView)).Nodes
If node.NavigateUrl = GetCurrentPage() Then
node.Expand()
Else
node.Collapse()
End If
Next

Resources