473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Rename a TreeNode

Hi all

I have a question abount renaming a selected treenode.
My user can place the cursor on a treeview, click on the right button of the
mouse, and a contextmenue is beeing populated, in which he can Add, rename
or delete a node from the treeview.

When he select the new option, the code I use is:

treeview1.Nodes.Add("New")

When he select the delete option, the code I use is:
treeview1.Nodes.Remove(treeview1.SelectedNode)

When he select the rename option, I need a code no let him change the
selected node's name.

How can I do it?

thanks

Aug 19 '08 #1
4 14605
ohad weiss wrote:
Hi all

I have a question abount renaming a selected treenode.
My user can place the cursor on a treeview, click on the right button of the
mouse, and a contextmenue is beeing populated, in which he can Add, rename
or delete a node from the treeview.

When he select the new option, the code I use is:

treeview1.Nodes.Add("New")

When he select the delete option, the code I use is:
treeview1.Nodes.Remove(treeview1.SelectedNode)

When he select the rename option, I need a code no let him change the
selected node's name.

How can I do it?

thanks
If you want to change the text (rename) of the selected node use:

TreeView1.SelectedNode.Text = "Your new text"

LS
Aug 19 '08 #2
Hi Lloyd ,

Thanks for your reply, but it seems that you didn't understand me.
I need to let my user rename it from the treeview itself, means, He stand on
the relevant node, click on it and it allow him to change it's name (like as
you rename a folder in the windows explorer)

"Lloyd Sheen" <a@b.cwrote in message
news:uB*************@TK2MSFTNGP06.phx.gbl...
ohad weiss wrote:
>Hi all

I have a question abount renaming a selected treenode.
My user can place the cursor on a treeview, click on the right button of
the mouse, and a contextmenue is beeing populated, in which he can Add,
rename or delete a node from the treeview.

When he select the new option, the code I use is:

treeview1.Nodes.Add("New")

When he select the delete option, the code I use is:
treeview1.Nodes.Remove(treeview1.SelectedNode)

When he select the rename option, I need a code no let him change the
selected node's name.

How can I do it?

thanks

If you want to change the text (rename) of the selected node use:

TreeView1.SelectedNode.Text = "Your new text"

LS

Aug 19 '08 #3
ohad weiss wrote:
Hi all

I have a question abount renaming a selected treenode.
My user can place the cursor on a treeview, click on the right button of the
mouse, and a contextmenue is beeing populated, in which he can Add, rename
or delete a node from the treeview.

When he select the new option, the code I use is:

treeview1.Nodes.Add("New")

When he select the delete option, the code I use is:
treeview1.Nodes.Remove(treeview1.SelectedNode)

When he select the rename option, I need a code no let him change the
selected node's name.

How can I do it?

thanks
I've used something like this:

Private Sub treeview1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles treeview1.KeyUp
'
' Catch special key F2
'
If e.KeyCode = Keys.F2 Then
treeview1.LabelEdit = True
treeview1.SelectedNode.BeginEdit()
End If

End Sub

Private Sub treeview1_AfterLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles treeview1.AfterLabelEdit
'
' Handle edited label and disable label edit
'
treeview1.LabelEdit = False
If e.Label Is Nothing OrElse e.Label.Trim.Length = 0 Then
' Can not be empty text
e.CancelEdit = True
End If

End Sub

Does not exactly answer, how to do it from the context menu, but I hope you'll get the idea.

- Timo
Aug 20 '08 #4
Hi ohad,

You call BeginEdit on the node. Also make sure that the treeview has
LabelEdit set to True
"ohad weiss" <oh***@netvision.net.ilwrote in message
news:eU*************@TK2MSFTNGP06.phx.gbl...
Hi Lloyd ,

Thanks for your reply, but it seems that you didn't understand me.
I need to let my user rename it from the treeview itself, means, He stand
on the relevant node, click on it and it allow him to change it's name
(like as you rename a folder in the windows explorer)

"Lloyd Sheen" <a@b.cwrote in message
news:uB*************@TK2MSFTNGP06.phx.gbl...
>ohad weiss wrote:
>>Hi all

I have a question abount renaming a selected treenode.
My user can place the cursor on a treeview, click on the right button of
the mouse, and a contextmenue is beeing populated, in which he can Add,
rename or delete a node from the treeview.

When he select the new option, the code I use is:

treeview1.Nodes.Add("New")

When he select the delete option, the code I use is:
treeview1.Nodes.Remove(treeview1.SelectedNode)

When he select the rename option, I need a code no let him change the
selected node's name.

How can I do it?

thanks

If you want to change the text (rename) of the selected node use:

TreeView1.SelectedNode.Text = "Your new text"

LS

Aug 20 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Benny Raymond | last post by:
More problems with this... When I run this code, the main form returns an invalid cast exception as it's executing the line "TreeNode n = (TreeNode) this.Nodes;" Does anyone know what would...
3
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
0
by: naija naija | last post by:
Hi All, I'm using the TreView Web Control for my MENU. And the Menu is populated from an XML file below. I want a way in which i can manipulate the XML when i want to manage it without having to...
0
by: fred | last post by:
I am using the clipboard to copy and paste a TreeNode but the Tag property does not seem to be copied. I use the Tag property for an Object that contains data relating to the TreeNode. The Tag...
5
by: Rothariger | last post by:
Hello.... i want to know if its posible to rename multiple files like windows does.. example: file zzzzzzz.doc file asdasd.doc file esfsefse.doc
3
by: tanya foster | last post by:
Hello, I am re-writing a visual basic .net application(visual studio 2003) in an asp.net application(visual studio 2005). The vb.net application relied on a treeview and hence, treenodes. The...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
1
by: jmDesktop | last post by:
I am trying to add nodes with keys to my treeview. I can add general nodes without problem with: //create new node TreeNode newNode = new TreeNode(myIdNumber); //create children TreeNode...
1
by: AAaron123 | last post by:
If you see this posted twice - sorry. My news reader showed my first post as "No Longer Available" I have the following in a .css file. The treeNodes behave as if they were "a" elements. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.