Accessing events from the default context menu.

6 posts, 0 answers
  1. Bruce
    Bruce avatar
    25 posts
    Member since:
    May 2017

    Posted 15 Aug Link to this post

    I am trying to identify when these events are fired, so that when someone use default context menu to add/delete/edit, I can respond in a different manner than simply anytime a node is added/deleted/edited.
  2. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 16 Aug Link to this post

    Hello Bruce,

    By default, you can use the EditedNodeAdded, and NodeRemoved events to handle the respective operations. 

    If you want to override the default actions you need to modify the default context menu and add new custom items: Modifying the Default Context Menu.

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Bruce
    Bruce avatar
    25 posts
    Member since:
    May 2017

    Posted 16 Aug in reply to Dimitar Link to this post

    I'm sorry if I was unclear, Those events seemingly are fired whenever a node is effected, regardless if this action was originated by the context menu, or if a node is added programmatically.

    I am trying to identify the origin of the event firing, specifically when it is done in the context menu.

    For example, when the user right clicks, and uses the context menu to add a new node, I want to trigger the edit method on the new node so they can directly edit it.  This behavior would be proper when the nodes are being added via a datasource or programmatically. 

  4. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 17 Aug Link to this post

    Hi Bruce,

    You cannot override the new behavior but you can replace the default item and use custom logic. Here is an example for this:
    private void RadTreeView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.TreeViewContextMenuOpeningEventArgs e
    {
        for (int i = e.Menu.Items.Count - 1; i >= 0; i--)
        {
            if (e.Menu.Items[i].Name == "New")
            {
                e.Menu.Items.Remove(e.Menu.Items[i]);
                var newItem = new RadMenuItem("Add Node");
                newItem.Click += NewItem_Click;
                e.Menu.Items.Insert(i, newItem);
                break;
            }
     
        }
    }
     
    private void NewItem_Click(object sender, EventArgs e)
    {
        var newNode = new RadTreeNode("New Node");
        RadTreeNode node = this.radTreeView1.SelectedNode;
        if (node == null)
        {
            return;
        }
     
        node.Nodes.Add(newNode);
        node.Expanded = true;
        this.radTreeView1.SelectedNode = newNode;   
        this.radTreeView1.BeginEdit();
    }

    Please let me know if there is something else I can help you with. 

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Bruce
    Bruce avatar
    25 posts
    Member since:
    May 2017

    Posted 17 Aug in reply to Dimitar Link to this post

    Is there a way to detect when a node is added from the context menu as opposed to any other method?

  6. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 18 Aug Link to this post

    Hello Bruce,

    No there is no built-in way to determine this. Perhaps you can use a flag when updating the tree view from your code:
    bool addingIncode = false;      
    private void button1_Click(object sender, EventArgs e)
    {
        addingIncode = true;
        radTreeView1.Nodes.Add("Test");
        addingIncode = false;
    }
    private void RadTreeView1_NodeAdded(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
    {
        if (addingIncode)
        {
            return;
        }
    }

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top