Edit tree node from code behind

11 posts, 1 answers
  1. om
    om avatar
    26 posts
    Member since:
    Jan 2009

    Posted 09 Sep 2009 Link to this post

    Hi,
    I just want to know that how can I be able edit a tree node from code behind, lets say, I added a node in my view model which is bound to tree itself and then as soon I add that new node in tree, I want to bring that node in edit mode, without user having pressed F2.
    Any thoughts ?
    Thanks
    OM
  2. Answer
    Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 10 Sep 2009 Link to this post

    Hi om,

    Use the IsInEditMode property of the TreeViewItem.

    Best wishes,
    Valentin.Stoychev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Peter
    Peter avatar
    1 posts
    Member since:
    Sep 2008

    Posted 03 Sep 2010 Link to this post

    Hi!

    I have to Edit an item but it is not a radtreeviewitem.

    I fill the nodes by a list (ItemSource), and when I add a new item to the datasource, I would like select and edit the new node.
    I resolved the selection: Binded the IsSelected property for the dataobject IsSelected, (ContainerBinding)

    BUT if I bind similar the IsInEditMode, and programitically set the IsInEditMode property of the data object, the textbox appear, but filled with the name of the type the data object and if I hit the enter key the textbox will be empty, and the size will be smaller.

    So, how can I edit a dataobject in a treeview?

    Thanks
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 07 Sep 2010 Link to this post

    Hi Peter,

    You can define an ItemEditTemplate to control what will be displayed when the items are in edit mode.
    For example you can try something like this:
    <telerikNavigation:RadTreeView ItemsSource="{Binding Items}" >
        <telerikNavigation:RadTreeView.ItemEditTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Header}"/>
            </DataTemplate>
        </telerikNavigation:RadTreeView.ItemEditTemplate>
        <telerikNavigation:RadTreeView.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Header}"/>
            </DataTemplate>
        </telerikNavigation:RadTreeView.ItemTemplate>
    </telerikNavigation:RadTreeView>

    Please give this approach a try and let me know if it works for you.

    Sincerely yours,
    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
  6. HL
    HL avatar
    55 posts
    Member since:
    Dec 2009

    Posted 08 Nov 2010 Link to this post

    hi all:
    I need to do the same function which OM wanted -- added the new node then make it editable without clicking any key. I couldn't find
    isInEditMode property for the node. I am guessing this property is for silverlight only. is it correct? I tried to use newNode.

    startEdit()
    but I always got error that "
    htmlfile: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."

    I submitted my issues several weeks ago and the solution I got from Telerilk is two solution
    1. adding this line code on the node click event "args.get_domEvent().stopPropagation();"
    2. called showMenu(event)
    none of them works. can any one please give me some suggestion? I feel so fructused for this issue and wonder get some help

    Basically I have one RadContextMent which has RadTreeview as the item. inside the RadTreeview , I have two TreeviewContextMenu.One is for parent node and the other one is for child node. when I right click the parent node or I right click the child node, the radtreeview disappear and only the RadTreeviewContextMenu exists.

    Can I get any one help?

    Thanks advanced

     



    my codes:
    <asp:imagebutton runat="server"  id="btnFavorite"   imageurl="../images/ToolBarImage/Favorite_a.gif"  height="25" width="33" borderwidth="0" alternatetext="Favorite"/>
    <telerik:RadContextMenu runat="server" ID="RadContextMenu1"  Skin="Outlook"  EnableRoundedCorners="true" TabIndex="1" AccessKey="T"  
       ClickToOpen="True" EnableShadows="true">         
            <Items>         
                <telerik:RadMenuItem>         
                   <ItemTemplate>
                         <telerik:RadTreeView ID="RadTreeViewFavorite"  runat="server" width="250px" 
                                OnClientContextMenuItemClicking="RadTreeViewFavorite_Client_ContextMenuItemClick" 
                                OnContextMenuItemClick ="RadTreeViewFavorite_ContextMenuItemClick" 
                                OnClientNodeClicking ="RadTreeViewFavorite_Client_NodeClick"   
                                 OnClientNodeClicked="RadTreeViewFavorite_Client_NodeClicked"
                                OnClientNodeChecking="RadTreeViewFavorite_onClientNodeCheck"  
                                OnNodeCheck="RadTreeViewFavorite_NodeCheck"       
                         AllowNodeEditing="true" Visible="true" CheckBoxes="true" MultipleSelect="true" >
                         <ContextMenus>  
                            <telerik:RadTreeViewContextMenu ID="Node_RTCM" runat="server"  Skin="Outlook"  ClickToOpen="true" >                          
                                <Items>  
                                    <telerik:RadMenuItem runat="server" Text="Rename" value="Rename" ToolTip="rename the select favorite name" >  
                                    </telerik:RadMenuItem>  
                                    <telerik:RadMenuItem runat="server" Text="Delete"  Value="Delete" ToolTip="delete current select Favorite" >  
                                    </telerik:RadMenuItem>  
                              </Items>  
                            </telerik:RadTreeViewContextMenu>  
                            <telerik:RadTreeViewContextMenu ID="Root_RTCM" runat="server" Skin="Outlook" ClickToOpen="true">                          
                                <Items>  
                                    <telerik:radmenuitem runat="server" Text="Add New Favorits"  Value="Add"/>  
                                </Items>  
                            </telerik:RadTreeViewContextMenu>  
                        </ContextMenus
                         <Nodes>
                                  <telerik:RadTreeNode Text="Favorite Lists" Expanded="True"  ContextMenuID="Root_RTCM" Checkable="false" Value="FavoriteRoot"  ></telerik:RadTreeNode
                         </Nodes>                           
                         </telerik:RadTreeView
                      </ItemTemplate>
                </telerik:RadMenuItem>         
            </Items>  
           <Targets>
                 <telerik:ContextMenuControlTarget ControlID="btnFavorite"/>
           </Targets>       
    </telerik:RadContextMenu
    <telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">
         <AjaxSettings>
                   <telerik:AjaxSetting AjaxControlID="RadTreeViewFavorite">
                       <UpdatedControls>
                           <telerik:AjaxUpdatedControl ControlID="RadContextMenu1" />
                       </UpdatedControls>
                        <UpdatedControls>
                           <telerik:AjaxUpdatedControl ControlID="RadTreeViewFavorite" />
                       </UpdatedControls>
                   </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="RadContextMenu1">
                       <UpdatedControls>
                           <telerik:AjaxUpdatedControl ControlID="RadContextMenu1" />
                       </UpdatedControls>
                   </telerik:AjaxSetting>
          </AjaxSettings>
     </telerik:RadAjaxManagerProxy


    javascript:
    //when user click the favorite image or mouse over, the menu should show up     
    function showMenu(e)
        {
            var contextMenu = $find("ctlSystemToolbar_ctlWucPopUpMenu1_RadContextMenu1");
            if ((!e.relatedTarget) || (!$telerik.isDescendantOrSelf(contextMenu.get_element(), e.relatedTarget)))
            {
                contextMenu.show(e);
            }
              
            $telerik.cancelRawEvent(e);
        }
          
      
    function RadTreeViewFavorite_Client_ContextMenuItemClick(sender, eventArgs)
       {
             //call in order the RadTreeview still display. won't work 
             showMenu(event)
                    
             var selectedItem = eventArgs.get_node();
             var selectedMenuOption = eventArgs.get_menuItem();
             var intCount
               
                  
             switch(selectedMenuOption.get_value())
              {
                case "Rename":
                    var contextMenu = selectedMenuOption.get_menu();
                    contextMenu.hide();
                    sender.trackChanges(); 
     
                    selectedItem.startEdit();  
                    eventArgs.set_cancel(true);
                    break;
                 case "Add":
                    intCount = selectedItem.get_nodes().get_count();
                    if (intCount >10)
                    {
                     alert("Maximum favorite name will be 10");
                     eventArgs.set_cancel(true);                                
                    }
                    else
                           //get error -- can't focus
                         selectedItem.startEdit();
                    break;
                      }
              
       }


  7. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 11 Nov 2010 Link to this post

    Hi Helena,

    This forum is for RadTreeView for Silverlight, please next time post such issues in the asp.net ajax forum.

    The reason for this error is that the when an item in the treeviewcontextmenu is clicked, the first context menu which actually holds the treeview is closed, so the node that you're trying to focus becomes invisible. I see that you discuss this issue in a another forum thread with my colleague Nikolay, could you please wait for his complete solution? Thanks

    Best regards,
    Yana
    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
  8. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 15 Jul 2011 Link to this post

    That is a very short answer, but not so helpfull

    I'm trying exactly this scenario from MVVM...

    I am using the ItemPrepared command in my viewmodel (is that the way to go?) and i can set
    ((RadTreeViewItemPreparedEventArgs)parameter).PreparedItem.IsInEditMode = true;

    The code is hit when i debug, but the item is not in Edit mode...

    I can edit using F2... so what am i doing wrong?

    (I am using 2011 Q 1)



  9. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 20 Jul 2011 Link to this post

    Hello Peter,

     Could you please elaborate more on your scenario? Why do you need to use the ItemPrepared event of the RadTreeView to start the edit mode ? Basically if you have non-virtualized RadTreeView with 100 items in the root level,  the ItemPrepared event will fire 100 times and then the loaded event of the RadTreeView will fire. It is expected that visually , there is no element in edit mode when you load your RadTreeView. So any additional info on your goal will be useful in order to advice you better. Thank you in advance.

    Kind regards,
    Petar Mladenov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  10. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 20 Jul 2011 Link to this post

    Hi Petar,

    I have treeview that is being used for creating a sort "New Folder" dialog.

    We are using the scripting host to read directories from the disk and we list them up in a treeview using LoadOnDemand (since the scripting host is way to slow to do it in one shot)

    We have a button on the bottom that says "New Folder", it will create a new subfolder in the selected folder, all of this is working just fine, except that we would the newly created node to be in edit mode immediately after adding it.

    I was able to get an event in after the creation of the node and then i set IsInEditMode = True... this is were it goes wrong, the tree will indeed react to the IsInEditMode because it clears the name of the node, but it does not display the textbox.

    Meanwhile an extra complication has arrisen that makes that approach (which "almost" worked) impossible. We need to sort the collection of sub folders on the selected folder so that "new folder" would be in the correct location (we are trying to approach windows explorer as close as possible), this means we have to first delete the collection of child nodes and reload them (or we have to sort the nodes).

    What i am asking is that if it is possible to get a collection of container objects after they were created (preferably in the event that fires after loadondemand is completed), so that i can executed the isineditmode on the appropriate node. I tried the various creation methods for containobject but without success.

    An Open/AddFolderDialog would be an absolute killer as a telerik control ;o)) especially on Silverlight5!


  11. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 21 Jul 2011 Link to this post

    Hello Peter,

    Please take a look at this recording and let me know if this is what you have in mind. If this is the case, then please take a look at the attached example as it explains how to achieve the desired result. If you have anything else in mind, do tell, I'll be glad to further assist you.

    Kind regards,
    Kiril Stanoev
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  12. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 21 Jul 2011 Link to this post

    Hi Kiril,

    That is EXACTLY what i was looking for!!!

    Thanks a million!

    Peter

Back to Top
DevCraft banner