This is a migrated thread and some comments may be shown as answers.

Allow only one child

1 Answer 21 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Gilbert van Veen
Top achievements
Rank 1
Gilbert van Veen asked on 01 Apr 2010, 09:52 AM
Hello Telerik friends,

I have the following situation:

Base -
          - A
          - B
          - C
          - D

This is the default treeview. Base is the root and A .. D are childs. I want the user to be able to move/reorder the childs around but they may not be moved to the root level (Base).  Every other child should be a child of a parent. Also each child can max. have only one other child. See below.

Valid structure:
Base -
           - A
               - B
                   - C
                      - D


Invald:
Base -
           - A
           - B
                   - C
                       - D

Also invalid:
Base -
           - A
               - B
                   - C
                   - D
Base -
           - A
               - B
                   - C
                   - D

In other words every child may be only a child of a parent. The "main" parent is Base, Is this possible?

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 06 Apr 2010, 06:32 PM
Hi Gilbert Van Veen,

In your case you have to handle the OnDropQuery() event and make sure that the items are dropped inside another item. You can do that by using the DropPosition property of the RadTreeViewItem.
 
if you also want to make sure that the destination item doesn't have other children  you can use the RadTreeViewItem HasItems property, and to check that the destination item isn't the root item of the tree you can use the RadTreeViewItem Level property, which is 0 only for the root items.

private void OnDropQuery(object sender, DragDropQueryEventArgs e)
    {
        RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;
        var dropPosition = item.DropPosition;
             
        if (dropPosition == DropPosition.Inside && !item.HasItems && item.Level != 0)
        {
            e.QueryResult = true;
            e.Handled = true;
        }
        else e.QueryResult = false;
    }

I have prepared an example for you. Please take a look at it and let me know if it works for you.


Kind regards,
Tina Stancheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
TreeView
Asked by
Gilbert van Veen
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or