I wonder how to edit Node text, currently F2 edit all the Node and not only Node text:
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)
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)
9 Answers, 1 is accepted
0
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.
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
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.
0
ner
Top achievements
Rank 1
answered on 20 Oct 2014, 11:24 AM
Thank you Desislava, this is exactly what i want !
BTW, is it possible to have Node text and the value in different colors ?
BTW, is it possible to have Node text and the value in different colors ?
0
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:
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Desislava
Telerik
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.
0
ner
Top achievements
Rank 1
answered on 20 Oct 2014, 03:32 PM
This way i can see the value twice and with 2 colors: red and blue because i am populate the node this way:
See my screenshot for the results.
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);
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.
0
ner
Top achievements
Rank 1
answered on 20 Oct 2014, 03:46 PM
i forgot to mention that i have several different Nodes with different names so i cannot just specify:
Ip address: will be different name next time.
e.NodeElement.ContentElement.Text =
"<html><color=red>Ip address: "
+
"<color=blue>"
+ e.Node.Value;
Ip address: will be different name next time.
0
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:
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Desislava
Telerik
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.
0
ner
Top achievements
Rank 1
answered on 24 Oct 2014, 09:10 AM
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:
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);
0
ner
Top achievements
Rank 1
answered on 24 Oct 2014, 09:13 AM
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);
0
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:
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
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.