如何添加到一个TreeView目录在运行时 [英] How to add to a TreeView directory at runtime

查看:111
本文介绍了如何添加到一个TreeView目录在运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TreeView控件中,我想允许用户从添加和删除子项。在探索基本功能,我使用的是按钮和 A 文本框添加这一分项目。当用户点击按钮新的树型视图需要创建并设置为我父母的一个子项 TreeView控件文本文本设置为子项的标题

I have a TreeView in which I would like to allow the user to add and delete subitems from. In exploring basic functionality I am using a button and a textbox to add this subitem. When the user clicks on the button a new TreeViewItem needs to be created and set as a subitem of my parent TreeView with the text from the textbox set as the subitem's Header.

这是 button_click 事件下我当前的代码

This is my current code under the button_click event:

//ADD T_ITEM TO PARENT TREEVIEW
private void button1_Click(object sender, RoutedEventArgs e)
{
       TreeViewItem item = new TreeViewItem();
       item.Header = textBox1.Text;

       //Compiler does not recognize "Nodes"
       Parent.Nodes.Add(item);
}



具体而言,编译器具有问题节点。我已经用来帮助我的主要问题使得很多的感觉,但只是不为我工作。所有我看过源在同一时间或其他没有问题的使用节点命令。 ?我需要包括一个参考,或者是我的代码完全关闭

Specifically, the compiler has a problem with Nodes. The main question that I've used to help me makes a lot of sense, but just doesn't work for me. All of the sources I have looked at uses the Nodes command at one time or another with no problem. Do I need to include a reference, or is my code completely off?

- 指南使用 System.Windows.Forms的; 为了使用节点,但似乎并没有帮助,因为我使用Windows Presentation Foundation中。

--This guide uses System.Windows.Forms; in order to use Nodes, but doesn't seem to help because I am using Windows Presentation Foundation.

请告诉我怎么把我的代码在正确的方向努力。

Please show me how to get my code working in the right direction.

感谢您。

推荐答案

我做了一些调查研究,发现等效方法添加孩子 TreeViewItems 母公司 TreeViewItems 在WPF。

I did some more research and found the equivalent method for adding child TreeViewItems to parent TreeViewItems in WPF.

这是改变我对代码所做的:

This is the change I made to my code:

//ADD T_ITEM TO PARENT TREEVIEW
private void button1_Click(object sender, RoutedEventArgs e)
{
      TreeViewItem item = new TreeViewItem();
      item.Header = textBox1.Text;

      Parent.Items.Add(item);
}

这篇关于如何添加到一个TreeView目录在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆