2013-03-25 73 views
0

我使用的是从Telerik的WinForms的2010年第三季radtreeview控制,我要做到以下几点,在加入应该在编辑模式下增加新的节点,以及这是在telerik 2010中不支持,所以我需要模拟按F2来使节点可编辑。 我发现这个线程关于同一主题:How to simulate pressing F2 button with keyboard focus on treeview in wpf?,但我需要做的是,在WinForm的WPF没有,你能帮帮我吗?如何模拟按F2键设置为可编辑TreeView节点

编辑 我用sendKeys方法+ tree.BeginEdit,但它没有解决! 这是我的代码:

private void radButton6_Click(object sender, EventArgs e) 
     { 
      RadTreeNode newNode = new RadTreeNode(); 
      newNode.Text = "new Cabinet"; 
      newNode.Tag = "new Cabinet"; 
      cabinetsTree.Nodes.Add(newNode); 
      cabinetsTree.SelectedNode = cabinetsTree.Nodes[cabinetsTree.Nodes.Count-1]; 
      cabinetsTree.ScrollToBottom(); //To set the focus on the new added node 
      cabinetsTree.Focus(); 
      cabinetsTree.AllowEdit = true; 
      SendKeys.Send("{F2}"); 
      cabinetsTree.BeginEdit(); 
     } 
+0

这将有助于http://www.telerik.com/community/forums/winforms/treeview/add-node-in-edit-mode-with-text.aspx – Daniil 2013-03-25 10:52:58

+0

EditorInitialized事件不是在Telerik的WinForm的2010年第三季度 – Lisa 2013-03-25 13:01:36

回答

1

你应该先允许在控制编辑节点,然后使用节点的BeginEdit方法:

public partial class Form1 : Form 
{ 
    RadTreeView tree = new RadTreeView(); 

    public Form1() 
    { 
     InitializeComponent(); 

     this.Controls.Add(tree); 
     tree.Size = new Size(500, 500); 
     tree.AllowEdit = true; 

    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     RadTreeNode newNode = new RadTreeNode(); 
     newNode.Text = "new Cabinet"; 
     tree.Nodes.Add(newNode); 
     newNode.BeginEdit(); 
    } 
} 
+0

我的问题是我在整个树上调用BeginEdit()而不是单个节点,谢谢你真的解决了它! – Lisa 2013-03-26 07:37:58

+0

不客气 – checho 2013-04-11 08:32:15

0

您可能能够通过捕捉你的键盘上的按键事件和编辑模式设置为true,每当你按下F2键来解决这个问题。

+0

用户可用不应该按F2,我只想按一下按钮at将在编辑模式下向树添加一个新节点。 – Lisa 2013-03-25 10:07:16

1

节点应该有一个BeginEdit()方法,其允许用户重命名该节点。基于documentation

使用BeginEdit()方法来启动编辑选择的节点上

+0

我使用WinForm的不是ASP.net ..这个文档是ASP.net – Lisa 2013-03-25 13:02:17

+0

我找不到自己的WinForms文档,但我认为,如果他们采用这种结构对于ASP.NET他们会使用它的WinForms以及。我认为该方法不存在于winforms呢? – coolmine 2013-03-25 13:03:52

+0

找到winforms文档,看看更新后的答案。 – coolmine 2013-03-25 13:11:25