TreeView question

S

Shawn

Hi.
I'm working with the TreeView control in my ASP.NET 1.1 application. I have
a problem I haven't been able to figure out. When I click on a node (not
expand), whether it's a parent node, a child node or a leaf node then a
DataGrid is populated based on the node's ID property. If I expand a node
then the DataGrid is not populated. This works fine. The problem is that
this doesn't work if I collapse the tree. If I collapse the tree then the
collapsed node is being selected (if the currently selected node is a
subnode of the node being collapsed) and the SelectedNodeChanged event is
fired. This causes the DataGrid to populate again. I've been thinking of a
way to avoid this, but I'm all out of ideas.

I thought of setting a flag when the collapse event was fired and then check
for that flag when the SelectedNodeChanged event fired to avoid populating
the DataGrid again. Problem is that the SelectedNodeChanged event fires
before the collapse event.

So, if there are any bright minds out there who can tell me what to do I
would be very grateful.

Thanks,
Shawn
 
S

Shawn

Hi.
The code isn't available right now, it's at work and I'm not going back
until next week.
The code isn't the problem though. I'll try and explain a little more.

In page_load the whole tree is generated. If I expand a node then nothing
is being done. If I click on a node then a DataGrid is filled based on the
node beeing clicked. This is done by calling my BindData() method from the
method that handles the SelectedNodeChanged event. That's it really, and it
workes like a charm.

Now, to the problem. If a node is selected and I click to collapse it's
parent node then the parent node becomes selected and the
SelectedNodeChanged event fires. This causes my DataGrid to fill up with new
data based on the parent node that is now selected. I don't want that to
happen since I haven't clicked on a node, I've just collapsed it.

I'm unable to tell whether a node has been selected or just collapsed. If
there is a way to know this then I could prevent the DataGrid from being
filled up with new data.

Shawn

Shawn maybe u can post some snippet code.
Patrick
 
S

Shawn

I came up with a solution. Though I might post it if anyone else has the
same problem.

Dim node As TreeNode
Dim arrayIndex As Array

'Check if the newly selected node is a parent of the previously selected
node.
If e.OldNode.StartsWith(e.NewNode) Then
arrayIndex = e.NewNode.Split("."c)

'Get the newly selected node.
If arrayIndex.Length = 1 Then
node = TreeView.Nodes(arrayIndex(0))
ElseIf arrayIndex.Length = 2 Then
node = TreeView.Nodes(arrayIndex(0)).Nodes(arrayIndex(1))
ElseIf arrayIndex.Length = 3 Then
node =
TreeView.Nodes(arrayIndex(0)).Nodes(arrayIndex(1)).Nodes(arrayIndex(2))
End If

'Only bind data to the DataGrid if this isn't a cause of collapsing the
TreeView.
If node.Expanded = True Then
BindData(e.NewNode)
End If
Else
BindData(e.NewNode)
End If


Hi.
The code isn't available right now, it's at work and I'm not going back
until next week.
The code isn't the problem though. I'll try and explain a little more.

In page_load the whole tree is generated. If I expand a node then nothing
is being done. If I click on a node then a DataGrid is filled based on the
node beeing clicked. This is done by calling my BindData() method from the
method that handles the SelectedNodeChanged event. That's it really, and it
workes like a charm.

Now, to the problem. If a node is selected and I click to collapse it's
parent node then the parent node becomes selected and the
SelectedNodeChanged event fires. This causes my DataGrid to fill up with new
data based on the parent node that is now selected. I don't want that to
happen since I haven't clicked on a node, I've just collapsed it.

I'm unable to tell whether a node has been selected or just collapsed. If
there is a way to know this then I could prevent the DataGrid from being
filled up with new data.

Shawn

Shawn maybe u can post some snippet code.
Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top