By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,536 Members | 1,800 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,536 IT Pros & Developers. It's quick & easy.

TreeView question

P: n/a
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
Apr 9 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Shawn maybe u can post some snippet code.
Patrick

"Shawn" <bo********@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
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

Apr 10 '06 #2

P: n/a
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

"Patrick.O.Ige" <na********@hotmail.com> wrote in message
news:e8**************@TK2MSFTNGP02.phx.gbl...
Shawn maybe u can post some snippet code.
Patrick

"Shawn" <bo********@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
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


Apr 10 '06 #3

P: n/a
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
"Shawn" <bo********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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

"Patrick.O.Ige" <na********@hotmail.com> wrote in message
news:e8**************@TK2MSFTNGP02.phx.gbl...
Shawn maybe u can post some snippet code.
Patrick

"Shawn" <bo********@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
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



Apr 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.