C# treeView修改一个节点的Text的问题
直接上代码
public string oldname = "";//修改前的名字
public string newname = "";//新名字
private void 修改名称ToolStripMenuItem_Click(object sender, EventArgs e)
{
oldname= SWTree.SelectedNode.Text;
SWTree.LabelEdit = true;
SWTree.SelectedNode.BeginEdit();
//System.IO.Directory.Move(apppath + @"/" + name, apppath + @"/" + SWTree.SelectedNode.Text);
}
private void SWTree_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
SWTree.LabelEdit = false;
newname = SWTree.SelectedNode.Text;
//System.IO.Directory.Move(apppath + @"/" + name, apppath + @"/" + SWTree.SelectedNode.Text);
}
获取到的newname和oldname 是相同的.
新手求大神!
------解决方案--------------------
private void SWTree_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
SWTree.LabelEdit = false;
this.BeginInvoke(
new MethodInvoker(
delegate {
newname = SWTree.SelectedNode.Text;
})
);
}