Udhay
Udhay

Reputation: 31

Rename Folder name when rename the tree node in the application

i rename the treeview treenode in application using keyword F2. After Renaming this, this name change should happen in the directory also..How do i know i have done edited name and it is changed and where can i call change directory name method.

 private void treeView_project_KeyDown(object sender, KeyEventArgs e)
    {
            if (e.KeyValue == (char)Keys.F2)
            {
                treeView_Project.SelectedNode.BeginEdit();
//here it is editing the treenode once it is done user should rename the folder also in the drive
            }
    }

Upvotes: 2

Views: 1009

Answers (2)

Coder14
Coder14

Reputation: 1277

If you know the path of the directory, you can rename the directory with these lines:

            try
            {
                DirectoryInfo di = new DirectoryInfo(path);
                di.MoveTo(di.Parent + "\\" + newName);
            }
            catch (Exception e)
            {
                //Changing directory name failed
            }

Upvotes: 1

SLaks
SLaks

Reputation: 887415

You're looking for the aptly-named AfterLabelEdit event.

Upvotes: 1

Related Questions