Home > Net >  Infragistics Selected Node
Infragistics Selected Node

Time:05-14

Would like to know if I am the error or I have encountered a bug.

I have a grid with parents and children. I have made buttons to move the nodes from top to bottom and back. This works, but the first selected node remains selected. The node that should be moved can be moved as desired. Why is the first selected node still displayed?

private void IDC_ARROW_UP_Click(object sender, System.EventArgs e)
{
    foreach (Infragistics.Win.UltraWinTree.UltraTreeNode Node in this.uTreeMenue.SelectedNodes)
    {
        Node.Reposition(Node, Infragistics.Win.UltraWinTree.NodePosition.Previous);
        Node.Selected = true;
    }
}

Selected node is shown below:

enter image description here

CodePudding user response:

Try the code below:

private void IDC_ARROW_UP_Click(object sender, System.EventArgs e)
{
    var selected = uTreeMenue.SelectedNodes;
    selected.SortByPosition();
    var cnt = selected.Count;
    if (cnt > 0 && selected[0].PrevVisibleNode is UltraTreeNode node) 
    {                
        node.Reposition(selected[cnt - 1], Infragistics.Win.UltraWinTree.NodePosition.Next);
    }
}

The logic implemented in the code above is very simple. Instead of moving all selected nodes (for example Canada…France on the picture below) up the first node located before all the selected items moving after all selected items down:

enter image description here

Therefore, after moving the node preceding all selected items down (in the test example this is Brazil item) the UltraTree control will be look like below:

enter image description here

To determine limits of the selected items correctly they are should be sorted by using the SortByPosition() method, that sorts the SelectedNodes collection such that members appear in the same order they do in the tree.

  • Related