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

Accessing events from the default context menu.

5 Answers 111 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 2
Bruce asked on 15 Aug 2017, 02:54 PM
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.

5 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 16 Aug 2017, 07:55 AM
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.
0
Bruce
Top achievements
Rank 2
answered on 16 Aug 2017, 04:15 PM

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. 

0
Dimitar
Telerik team
answered on 17 Aug 2017, 07:35 AM
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.
0
Bruce
Top achievements
Rank 2
answered on 17 Aug 2017, 02:39 PM

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

0
Dimitar
Telerik team
answered on 18 Aug 2017, 07:57 AM
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.
Tags
Treeview
Asked by
Bruce
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
Bruce
Top achievements
Rank 2
Share this question
or