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

selecting and expanding inserted item

3 Answers 85 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
Morten asked on 03 Feb 2012, 12:19 AM
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.

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 07 Feb 2012, 05:33 PM
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 >>
0
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 07 Feb 2012, 07:41 PM
Hi Tsvetina
i'm doing insert and updates manually in the InsertCommand and UpdateCommand events.
/Morten
0
Accepted
Tsvetina
Telerik team
answered on 09 Feb 2012, 10:59 AM
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 >>
Tags
TreeList
Asked by
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Tsvetina
Telerik team
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or