C# TreeView 添加子项后怎么让新子项获得焦点?

2025-01-07 03:24:05
推荐回答(2个)
回答1:

NodeMouseClick触发后估计有执行了其他东西,这得跳出这个堆栈显示窗体。
一个BT的方式:加一个计时器,通过激活计时器打开窗体。

C# code
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
Form form = new Form();
form.Show();
}
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
timer1.Interval = 1;
timer1.Enabled = true;
}

回答2:

this.treeView2.SelectedNode.Nodes.Add(new TreeNode("商品分类_新类"));
this.treeView2.Focus();
this.treeView2.SelectedNode.BeginEdit();

//改成这样
TreeNode nd = new TreeNode("商品分类_新类")

this.treeView2.SelectedNode.Nodes.Add(nd );
this.treeView2.SelectedNode = nd ;