Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
790
How to set one node to Active and other node to selected and edit mode in XamDataTree
posted

Hi,

I have a scenario that should work just like windows explorer (new folder creation).

When I create a child node under a parent node, I want the parent node to be still active and the created child node to enter into the edit mode. In this case if I create another child node it should get added to the parent node. 

I'm unable to get this scenario worked with the following code. Please help

private void ExpandSelectActive(NodeBase parent, NodeBase childNode)
{
if (PpStructureTree != null)
{
//Expand and Active
var nodeTobeExpanded = PpStructureTree.ActiveNode;
if (nodeTobeExpanded == null && parent != null)
{
var nodes = PpStructureTree.GetNodesFromItems(new object[] { parent }, true);
nodeTobeExpanded = nodes.FirstOrDefault();
}

if (nodeTobeExpanded != null)
{
nodeTobeExpanded.IsExpanded = true;
nodeTobeExpanded.IsActive = true;
nodeTobeExpanded.IsSelected = false;
activeNode = parent;
}

//Select
if (childNode != null)
{
var nodes = PpStructureTree.GetNodesFromItems(new object[] { childNode }, true);
var nodeTobeSelected = nodes.FirstOrDefault();
if (nodeTobeSelected != null)
{
//nodeTobeSelected.IsSelected = true;
//nodeTobeSelected.IsActive = false;
PpStructureTree.EnterEditMode(nodeTobeSelected);
}
}
}
}

Thanks,

Sreeni

  • 34810
    Verified Answer
    Offline posted

    Hello Sreeni,

    Thank you for your post!

    Unfortunately, the requirement you are looking to achieve is not possible with the current implementation of the XamDataTree, because for a XamDataTree node to be in edit mode, it needs to be the active node. I imagine the behavior you are currently seeing with the code you have provided is that your new "nodeToBeSelected" is visible, is selected, and is in edit mode, but the "nodeToBeExpanded" is not the Active node. This is because when you enter edit mode on a node, that node will become the active node.

    I'm not sure if it would help you on the requirement you are looking to achieve, but the reverse of what you are currently doing is possible. You can set a different node to be selected while one is in edit mode. If the requirement you are looking to achieve is by perchance to keep track of the parent node and place the child node in edit mode, I would recommend that you take a look at the sample project I have attached. This sample activates the new node and places it in edit mode, but allows the parent node to remain selected.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    XamDataTreeActiveSelectEditCase.zip