selecting and expanding inserted item

4 posts, 1 answers
  1. Morten
    Morten avatar
    267 posts
    Member since:
    Jul 2012

    Posted 02 Feb 2012 Link to this post

    Is there a smart way to expand the parent of an inserted item and to select the inserted item.
    In the demos items are added to a collapsed parent. It would be a better user experience.
  2. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 07 Feb 2012 Link to this post

    Hi Morten,

    Thank you for contacting us.

    The approach would depend on the way you are performing CRUD operations in the treelist. If you use automatic operations, you can expand the parent item on ItemInserted event. Then, on PreRender you can select the newly added child item.

    If you perform manual operations, you will most probably need to do both things on PreRender but depending on a few other factors, we can move the expand to an earlier event to prevent a second Rebind() of the treelist.

    In any case, we would need to know more about your treelist setup in order to give you a working code snippet. Therefore, could you paste your control declaration and describe how you perform inserts in it?

    Greetings,
    Tsvetina
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Morten
    Morten avatar
    267 posts
    Member since:
    Jul 2012

    Posted 07 Feb 2012 Link to this post

    Hi Tsvetina
    i'm doing insert and updates manually in the InsertCommand and UpdateCommand events.
    /Morten
  5. Answer
    Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 09 Feb 2012 Link to this post

    Hi Morten,

    You can do the following on ItemCommand, as long as you use EditForms/PopUp editing :
    int? parentIndex = null;
    protected void RadTreeList1_ItemCommand(object sender, TreeListCommandEventArgs e)
    {
        if (e.CommandName == RadTreeList.PerformInsertCommandName)
        {
            TreeListDataItem item = (e.Item as TreeListEditFormInsertItem).ParentItem;
            parentIndex = item.DataItemIndex;
        }
    }
    protected void RadTreeList1_PreRender(object sender, EventArgs e)
    {
        if (parentIndex != null)
        {
            TreeListDataItem parent = RadTreeList1.Items[(int)parentIndex];
            RadTreeList1.ExpandItemToLevel(parent, parent.HierarchyIndex.NestedLevel + 1);
        }
    }

    For InPlace, cast e.Item directly to TreeListDataItem.

    As for selecting the inserted child, as the DataKeyValue of the inserted item is usually not known upon insertion, you would need to recognize the item in PreRender by some other value that is available during the insert and select it.

    All the best,
    Tsvetina
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top