Context Menu in Node and Sub Node Issue

4 posts, 0 answers
  1. Sasmita
    Sasmita avatar
    19 posts
    Member since:
    Jul 2008

    Posted 14 Jul 2008 Link to this post

    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 

  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 17 Jul 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sasmita
    Sasmita avatar
    19 posts
    Member since:
    Jul 2008

    Posted 22 Jul 2008 Link to this post

    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;

    }

    }

    }

  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 24 Jul 2008 Link to this post

    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.
Back to Top