RadTree with Context Menu using windows forms

9 posts, 0 answers
  1. SHD
    SHD avatar
    19 posts
    Member since:
    Apr 2007

    Posted 28 Feb 2008 Link to this post

    I want to build a RadTree with a Context Menu using a windows forms application. Can you please point me to some code samples/sample application?
    I found the online demos for the ASP.Net RadTree, but did not see any samples for their windows counterpart.

    Thank you.
  2. SHD
    SHD avatar
    19 posts
    Member since:
    Apr 2007

    Posted 28 Feb 2008 Link to this post

    I drag and dropped a RadTreeView control onto a windows form.

    For one, it shows the control on a panel below the form, not on the form itself. In the .cs code I am doing this:

    InitializeComponent();

    List<NameValue> list = new List<NameValue>();
    list.Add(
    new NameValue("node1", "value1"));
    list.Add(
    new NameValue("node2", "value2"));
    list.Add(
    new NameValue("node3", "value3"));
    radTreeView1.DisplayMember =
    "ID";
    radTreeView1.ValueMember =
    "Value";
    radTreeView1.DataSource = list;

    I do not see the tree displayed on the form with these 3 nodes.
    I have Winforms Q1 2007.

    Do you have an idea what is going on?

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 29 Feb 2008 Link to this post

    Hello SHD,

    You can find the online documentation of RadControls for WinForms here:
    http://www.telerik.com/help/winforms/Q3_2007/

    Here is a help article showing how one can bind a RadTreeView to a List (as in your sample code):
    http://www.telerik.com/help/winforms/Q3_2007/RadTreeDataBasics.html

    Here is another help article explaining how to use context menus with RadTreeView:
    http://www.telerik.com/help/winforms/Q3_2007/RadTreeDesignContextMenus.html

    I hope that helps. If you have any further questions do not hesitate to ask.

    Greetings,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. SHD
    SHD avatar
    19 posts
    Member since:
    Apr 2007

    Posted 29 Feb 2008 Link to this post

    Thank you for your help. 

    Can you please point me to sample code that illustrates how to control the appearance of a radTreeView using themes and styles? Specifically based on some application logic I want to change the background of certain leaf nodes in the tree.

    Also, there is a RadMenu object in the ToolBox and a RadMenuStrip object in documentation. Can any of these be used for rendering context menus? I am using the RadDropDownMenu for rendering my context menu.

    Thank you in advance.
  6. SHD
    SHD avatar
    19 posts
    Member since:
    Apr 2007

    Posted 03 Mar 2008 Link to this post

    I have the RadDropDownMenu context menu hooked to a tree.
    When I right click and select an option from the context menu, I want to determine the node of the tree on which the context menu was clicked.
    Note that this node may not be selected at this point.

    Thank you.
  7. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 04 Mar 2008 Link to this post

    Hello SHD,

    To control the appearance of RadTreeNode you have to use some of its properties, such as ForeColor, ForeColor2, BorderColor, BackColor, BackColor2, BackColor3. BackColor4. GradientAngle, GradientPercentage, GradientPercentage2, GradientStyle and NumberOfColors. These are used to control the visual appearance of any Telerik WinForms control. Please, review the documentation on how to change the visual appearance of the controls.

    To determine the node of the tree on which the context menu was clicked, subscribe to the MouseUp event of RadTreeView and then add the following code:
      
    void radTreeView1_MouseUp(object sender, MouseEventArgs e)
    {
        
    if (e.Button == MouseButtons.Right)
         {
                RadTreeNode node = this.radTreeView1.GetNodeAt(e.Location.X, e.Location.Y);

                if (node != null)
                {

                    // TO DO
                }
          }
    }

    As to RadMenu and RadMenuStip - they are the same objects. We will rename them all to RadMenuStrip in one of the future versions. The RadDropDownMenu you are currently using should help you achieve your goal.

    This should help you. Please write us back if you have other questions.


    Regards,

    Boyko Markov
    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center
  8. SHD
    SHD avatar
    19 posts
    Member since:
    Apr 2007

    Posted 11 Mar 2008 Link to this post

    Thank you Boyko for the information. It worked for me.

    Can you please tell me how can I search for nodes by text in a RadTree?
    I see a FindNodeByText on the ASP.Net RadTree but no equivalent on the windows forms RadTree.

    Thank you.
  9. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 14 Mar 2008 Link to this post

    Hi SHD,

    Currently, RadTreeView does not support the FindNodeByText feature. This issue will be addressed for the Q1 2008 release. For the time being, please refer to the following code snippet representing the implementation of the method:
    RadTreeNode FindNodeByText(RadTreeNodeCollection nodeCollection, string text)  
    {  
        foreach (RadTreeNode node in nodeCollection)  
        {  
            if ((node.Text == text) && (node != this.radTreeView1.SelectedNode))  
            {  
                return node;  
            }  
            RadTreeNode result = this.FindNodeByText(node.Nodes, text);  
            if (result != null)  
            {  
                return result;  
            }  
        }  
     
        return null;  

    I hope this helps. If you have additional questions, do not hesitate to contact me.

    Regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 23 Mar 2011 Link to this post

    Hi SHD,

    Please note that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out. For more information on our latest release refer to this blog post.

    Kind regards,
    Stefan
    the Telerik team
Back to Top
UI for WinForms is Visual Studio 2017 Ready