TreeView question

Discussion in 'ASP .Net' started by Shawn, Apr 9, 2006.

  1. Shawn

    Shawn Guest

    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
     
    Shawn, Apr 9, 2006
    #1
    1. Advertising

  2. Shawn maybe u can post some snippet code.
    Patrick

    "Shawn" <> wrote in message
    news:%233fzdV%...
    > 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
    >
    >
     
    Patrick.O.Ige, Apr 10, 2006
    #2
    1. Advertising

  3. Shawn

    Shawn Guest

    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" <> wrote in message
    news:e8$...
    Shawn maybe u can post some snippet code.
    Patrick

    "Shawn" <> wrote in message
    news:%233fzdV%...
    > 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
    >
    >
     
    Shawn, Apr 10, 2006
    #3
  4. Shawn

    Shawn Guest

    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" <> wrote in message
    news:%...
    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" <> wrote in message
    news:e8$...
    Shawn maybe u can post some snippet code.
    Patrick

    "Shawn" <> wrote in message
    news:%233fzdV%...
    > 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
    >
    >
     
    Shawn, Apr 12, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VHltYm93?=
    Replies:
    2
    Views:
    24,544
    =?Utf-8?B?VHltYm93?=
    Jan 10, 2006
  2. abargaddon
    Replies:
    0
    Views:
    1,089
    abargaddon
    Jan 17, 2008
  3. Per Salmi

    TreeView not rendering nodes? Cacheing of a TreeView

    Per Salmi, Oct 15, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    491
    Steve Drake
    Oct 15, 2003
  4. Ionutz
    Replies:
    2
    Views:
    546
    Ionutz
    Oct 23, 2005
  5. stepkurt

    Microsoft Treeview vs System Treeview

    stepkurt, Aug 29, 2007, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    400
    Teemu Keiski
    Sep 2, 2007
Loading...

Share This Page