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

Context Menu in Node and Sub Node Issue

3 Answers 115 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Sasmita
Top achievements
Rank 1
Sasmita asked on 14 Jul 2008, 10:02 PM

Hi ,

I am using a RadTreeNode, tree Structure is given below.                         

Label-0
       Label0-1 -- Context Menu -1 is assigned to this node
               Label0-1-1 Context Menu -2 is assigned to this node
               Label0-1-2 Context Menu -2 is assigned to this node

        Label0-2
              Label0-2-1
                Label0-2-2  
Label-1
                    

I have assigned Context Menu -1” to  Label0-1 and Context Menu -2” to Label0-1-1  as shown above .

When I do a right click on node Label0-1-1, for first time “Context Menu 1” 1 is showing , next time when I do a right click then it’s showing “Context Menu 2”. I mean sub nodes are showing the context menu of the Parent node for the first time and second time when you do a right click it shows the proper context menu. 

Could any body please help me out .

Sasmita 

3 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 17 Jul 2008, 12:07 PM
Hi Sasmita,

I tried to reproduce the issue you describe but to no avail. I've tried using the Q1 2008 SP1 version so I am making a guess that it must be an issue related to an older version of RadControls for WinForms. Could you, please elaborate a bit more and tell me which version you are using?

You can find attached the sample project that I used for testing.

Looking forward to your reply.

All the best,
Jordan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Sasmita
Top achievements
Rank 1
answered on 22 Jul 2008, 05:10 PM

Hi I am so sorry. I could not attach the solution file which i had developed for testing.

Could you please just look at the below code and let me know where i am wrong.

In the Form_Load event i am Creating the Tree View and in the 
ContextMenuShowing event i am assigning the respective Context Menus to nodes.

So when i first time click on the Node 1 and Node 2 they are showing Level 0 only and for second time onwards,  they are showing the proper context menu assigned to them.

Regards,
Sasmita



using

System;

using

System.Collections.Generic;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Linq;

using

System.Text;

using

System.Windows.Forms;

using

Telerik.WinControls.UI;

namespace

TelerikWindowsFormsApplication

{

public partial class Form1 : Form

{

RadDropDownMenu menu = new RadDropDownMenu();

RadDropDownMenu menu1 = new RadDropDownMenu();

RadDropDownMenu menu2 = new RadDropDownMenu();

public Form1()

{

InitializeComponent();

}

 

private void Form_Load(object sender, EventArgs e)

{

RadMenuItem item = new RadMenuItem("Level 0 ");

menu.Items.Add(item);

RadMenuItem item1 = new RadMenuItem("Level 1");

menu1.Items.Add(item1);

RadMenuItem item2 = new RadMenuItem("Level 2");

menu2.Items.Add(item2);

 

 

string xmlTree = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"

+

"<TreeView xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" AllowDrop=\"true\" BackColor=\"Transparent\">"

+

"<Nodes Expanded=\"true\" Text=\"Node1\"> "

+

" <Nodes Expanded=\"true\" Text=\"Node4\">"

+

" <Nodes Text=\"Node5\" /> "

+

" <Nodes Text=\"Node6\" />"

+

" </Nodes>"

+

"<Nodes Expanded=\"true\" Text=\"Node7\"> "

+

" <Nodes Expanded=\"true\" Text=\"Node8\">"

+

" <Nodes Text=\"Node9\" />"

+

"</Nodes> "

+

"</Nodes>"

+

"</Nodes> "

+

"<Nodes Text=\"Node2\" />"

+

"<Nodes Text=\"Node3\" /> "

+

"</TreeView>";

 

radTreeViewTest.TreeViewXml = xmlTree;

radTreeViewTest.ExpandAnimation =

ExpandAnimation.Opacity;

radTreeViewTest.ContextMenuShowing +=

new EventHandler<ContextMenuShowingEventArgs>(radTreeViewTest_ContextMenuShowing);

radTreeViewTest.RadContextMenu = menu;

}

private void radTreeViewTest_ContextMenuShowing(object sender, ContextMenuShowingEventArgs e)

{

if (e.Node.Level == 0)

e.Node.ContextMenu = menu;

if (e.Node.Level == 1)

e.Node.ContextMenu = menu1;

if (e.Node.Level == 2)

e.Node.ContextMenu = menu2;

}

}

}

0
Jordan
Telerik team
answered on 24 Jul 2008, 02:29 PM
Hi Sasmita,

I tried the code and I believe that I found the solution.
In order to apply the menu right away, you need to set the ContextMenu property to the event arguments like:
private void radTreeViewTest_ContextMenuShowing(object sender, ContextMenuShowingEventArgs e) 
        { 
            if (e.Node.Level == 0) 
            { 
                e.ContextMenu = menu; 
                e.Node.ContextMenu = menu; 
            } 
 
            if (e.Node.Level == 1) 
            { 
                e.ContextMenu = menu1; 
                e.Node.ContextMenu = menu1; 
            } 
 
            if (e.Node.Level == 2) 
            { 
                e.ContextMenu = menu2; 
                e.Node.ContextMenu = menu2; 
            } 
        } 

Please, give it a try and tell us if you have further problems.

Sincerely yours,
Jordan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Treeview
Asked by
Sasmita
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Sasmita
Top achievements
Rank 1
Share this question
or