How to rename directly in the TreeView node?
-
Hi, Do you people know when you click once in a treeview node in explorer for example? We can then rename directly that item. What do i need to do in order to implement that? Thx, Nuno
-
Hi, Do you people know when you click once in a treeview node in explorer for example? We can then rename directly that item. What do i need to do in order to implement that? Thx, Nuno
You may create a custom control that on the rename shortcut converts the node head to a textbox and take the text and set it . OR Handle the F2 shortcut for example, and pop a custom messagebox up, take the new name, and set the text to it.
-
Hi, Do you people know when you click once in a treeview node in explorer for example? We can then rename directly that item. What do i need to do in order to implement that? Thx, Nuno
Here is some code, you can refer, string
selectedNodeText;
private void RenametoolStripMenuItem_Click(object sender, EventArgs e)
{
TreeNode node = this.treeView.SelectedNode as TreeNode;
selectedNodeText = node.Text;
this.treeViewTestplan.LabelEdit = true;
node.BeginEdit();
}void treeView\_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e) { TreeNode node = this.treeView.SelectedNode as TreeNode; this.treeViewTestplan.LabelEdit = false; if (e.Label.IndexOfAny(new char\[\] { '\\\\', '/', ':', '\*', '?', '"', '<', '>', '|' }) != -1) { MessageBox.Show("Invalid StepName.\\n" + "The step Name must not contain " + "following characters:\\n \\\\ / : \* ? \\" < > |", "step name Edit Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrWhiteSpace(e.Label)) { MessageBox.Show("Step name is Invalid"); e.CancelEdit = true; return; }
string label = (!string.IsNullOrEmpty(e.Label) ? e.Label :selectedNodeText);
if (null != e.Label)
{
(node.ExecutionObject as Step).Name = label;} } void treeView\_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.F2) { this.RenametoolStripMenuItem\_Click(this, null); } }