Edit only Node test and not all Node

10 posts, 0 answers
  1. ner
    ner avatar
    8 posts
    Member since:
    Oct 2014

    Posted 15 Oct 2014 Link to this post

    I wonder how to edit Node text, currently F2 edit all the Node and not only Node text:

    radTreeView1.AllowEdit = true;
    radTreeView1.BeginEdit();
    RadTreeNode ethernetNode = radTreeView1.Nodes.Add("Ip address: 0.0.0.0");

    Note that i am not using bound but just regular node creation like in my code example, please see my screenshot, can i edit only my text ? (in my example this is 0.0.0.0)
  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 20 Oct 2014 Link to this post

    Hello Ner,

    Thank you for writing.

    By default when RadTreeView is in unbound mode modifying the Text or the Value property of a node will automatically update the other one. This behavior can be controlled via the EditMode property of the TreeViewElement. In the provided example, the RadTreeNode.Text property is set to "Ip address: 0.0.0.0", not only the "0.0.0.0" part. That is why the whole text is editable. You can use the TreeNodeEditMode.Value and assign the desired part ( "0.0.0.0" ) as value. Thus, when the RadTreeView is not in edit mode, it will be displayed the RadTreeNode.Text property. When entering edit mode, the RadTreeNode.Value will be displayed and ready for editing. However, when the Value is modified, you should update the Text respectively.
    public Form1()
    {
        InitializeComponent();
     
        radTreeView1.AllowEdit = true;
     
        RadTreeNode ethernetNode = new RadTreeNode();
        ethernetNode.Text = "Ip address: 0.0.0.0";
        ethernetNode.Value = "0.0.0.0";
        radTreeView1.Nodes.Add(ethernetNode);
     
        radTreeView1.TreeViewElement.EditMode = TreeNodeEditMode.Value;
        radTreeView1.Edited += radTreeView1_Edited;
    }
     
    private void radTreeView1_Edited(object sender, TreeNodeEditedEventArgs e)
    {
        e.Node.Text = "Ip address: " + e.Node.Value;
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. ner
    ner avatar
    8 posts
    Member since:
    Oct 2014

    Posted 20 Oct 2014 in reply to Dess Link to this post

    Thank you Desislava, this is exactly what i want !
    BTW, is it possible to have Node text and the value in different colors ? 
  5. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 20 Oct 2014 Link to this post

    Hello Ner,

    Thank you for writing back.

    You can assign different fore color for different text parts using our HTML-like Text Formatting functionality. It can be applied to the NodeElement.ContentElement.Text property in the NodeFormatting event. Additionally, if you want to customize the fore color for the TreeViewTextBoxEditor it is appropriate to use the EditorInitialized event:
    radTreeView1.NodeFormatting += radTreeView1_NodeFormatting;
    radTreeView1.EditorInitialized+=radTreeView1_EditorInitialized;

    //specify the editor's forecolor
    private void radTreeView1_EditorInitialized(object sender, TreeNodeEditorInitializedEventArgs e)
    {
        TreeViewTextBoxEditor editor = e.Editor as TreeViewTextBoxEditor;
        if (editor !=null)
        {
            BaseTextBoxEditorElement  element = editor.EditorElement as BaseTextBoxEditorElement;
            element.ForeColor = Color.Blue;
        }
    }
     
    //specify different forecolor for the text parts
    private void radTreeView1_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
    {
        e.NodeElement.ContentElement.Text = "<html><color=red>Ip address: " + "<color=blue>" + e.Node.Value;
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. ner
    ner avatar
    8 posts
    Member since:
    Oct 2014

    Posted 20 Oct 2014 in reply to Dess Link to this post

    This way i can see the value twice and with 2 colors: red and blue because i am populate the node this way:

                RadTreeNode destinationAddressNode = new RadTreeNode();
                destinationAddressNode.Text = "Destination address: FF:FF:FF:FF:FF:FF";
                destinationAddressNode.Value = "FF:FF:FF:FF:FF:FF";
                ethernetNode.Nodes.Add(destinationAddressNode);

    See my screenshot for the results.
  7. ner
    ner avatar
    8 posts
    Member since:
    Oct 2014

    Posted 20 Oct 2014 in reply to ner Link to this post

    i forgot to mention that i have several different Nodes with different names so i cannot just specify:

    e.NodeElement.ContentElement.Text = "<html><color=red>Ip address: " + "<color=blue>" + e.Node.Value;

    Ip address: will be different name next time.
  8. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 23 Oct 2014 Link to this post

    Hello Ner,

    Thank you for writing back.

    You can use the RadTreeNode.Name property to assign the desired name. The RadTreeNode.Value property will indicate the corresponding value. Thus, in the NodeFormatting event, you will be able to construct the NodeElement.ContentElement.Text by concatenating the Node.Name and the Node.Value properties:
    public Form1()
    {
        InitializeComponent();
     
        radTreeView1.AllowEdit = true;
     
        RadTreeNode ethernetNode = new RadTreeNode();
        ethernetNode.Name = "Ip address:";
        ethernetNode.Value = "0.0.0.0";
        radTreeView1.Nodes.Add(ethernetNode);
     
        RadTreeNode destinationNode = new RadTreeNode();
        destinationNode.Name = "Destination address:";
        destinationNode.Value = "FF:FF:FF:FF:FF:FF";
     
        radTreeView1.Nodes.Add(destinationNode);
     
        radTreeView1.TreeViewElement.EditMode = TreeNodeEditMode.Value;
    }
     
    //specify different forecolor for the text parts
    private void radTreeView1_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
    {
        e.NodeElement.ContentElement.Text = "<html><color=red>" + e.Node.Name + "<color=blue>" + e.Node.Value;
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  9. ner
    ner avatar
    8 posts
    Member since:
    Oct 2014

    Posted 24 Oct 2014 in reply to Dess Link to this post

    When i am using Name property i cannot see the value unless i try to edit the Node and press F2,
    this is how i am populate mu Node:

    RadTreeNode destinationAddressNode = new RadTreeNode();
    destinationAddressNode.Name= "Destination address: " + "FF:FF:FF:FF:FF:FF";
    destinationAddressNode.Value = packet.Ethernet.Destination.ToString();
    ethernetNode.Nodes.Add(destinationAddressNode);
  10. ner
    ner avatar
    8 posts
    Member since:
    Oct 2014

    Posted 24 Oct 2014 in reply to ner Link to this post

    Sorry, this is the corrent way:

    RadTreeNode destinationAddressNode = new RadTreeNode();
                destinationAddressNode.Name= "Destination address: ";
                destinationAddressNode.Value = "FF:FF:FF:FF:FF:FF":
                ethernetNode.Nodes.Add(destinationAddressNode);
  11. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 28 Oct 2014 Link to this post

    Hello Ner,

    Thank you for writing back.

    I suppose that you missed to subscribe to the NodeFormatting event and specify the NodeElement.ContentElement.Text property. Here is the whole code snippet from my sample project:
    public Form1()
    {
        InitializeComponent();
     
        radTreeView1.AllowEdit = true;
     
        RadTreeNode ethernetNode = new RadTreeNode();
        ethernetNode.Name = "Ip address:";
        ethernetNode.Value = "0.0.0.0";
        radTreeView1.Nodes.Add(ethernetNode);
     
        RadTreeNode destinationNode = new RadTreeNode();
        destinationNode.Name = "Destination address:";
        destinationNode.Value = "FF:FF:FF:FF:FF:FF";
     
        radTreeView1.Nodes.Add(destinationNode);
     
        radTreeView1.TreeViewElement.EditMode = TreeNodeEditMode.Value;
        radTreeView1.Edited += radTreeView1_Edited;
         
        radTreeView1.NodeFormatting += radTreeView1_NodeFormatting;
        radTreeView1.EditorInitialized += radTreeView1_EditorInitialized;
    }
     
    //specify different forecolor for the text parts
    private void radTreeView1_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
    {
        e.NodeElement.ContentElement.Text = "<html><color=red>" + e.Node.Name + "<color=blue>" + e.Node.Value;
    }
     
    //specify the editor's forecolor
    private void radTreeView1_EditorInitialized(object sender, TreeNodeEditorInitializedEventArgs e)
    {
        TreeViewTextBoxEditor editor = e.Editor as TreeViewTextBoxEditor;
        if (editor != null)
        {
            BaseTextBoxEditorElement element = editor.EditorElement as BaseTextBoxEditorElement;
            element.ForeColor = Color.Blue;
        }
    }
     
    private void radTreeView1_Edited(object sender, TreeNodeEditedEventArgs e)
    {
        e.Node.Text = "Ip address: " + e.Node.Value;
    }

    If you are still experiencing any difficulties, it would be greatly appreciated if you provide a complete code snippet reproducing the undesired behavior. Thus, we would be able to investigate the precise case and assist you further. Thank you.

    I hope this information helps. If you have any additional questions, please let me know.
     
    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready