外部带有文本框的树状视图

问题描述

| 目前,我正在使用Treeview。 除了treeview,还有3个文本框。 通过单击树视图的节点,我需要启用文本框。 程序就是这样。 如果我在第一个文本框中编写文本,则该文本应显示在treeview的第一个节点的子节点中 通过单击该节点,应启用第二个文本框。 这对于应该启用的3个文本框应该相同。 我在文本框中编写并在节点中复制的所有文本都应保存在数据库中。     

解决方法

我假设在您的treeview节点中存在。 如果没有,我的代码给你一些错误。 所有三个文本框的OnTextChanged事件都必须引用“ 0”方法。 响应1/2/3:
public partial class Form1 : Form
{
    TreeNode first,child01,child02,child03;

    public Form1()
    {
        InitializeComponent();
        treeView1.ExpandAll();

        first = treeView1.Nodes[0];
        child01 = first.Nodes[0];
        child02 = first.Nodes[1];
        child03 = first.Nodes[2];
    }

    private void textBox_TextChanged(object sender,EventArgs e)
    {
        if (sender == textBox1) child01.Text = textBox1.Text;
        else if (sender == textBox2) child02.Text = textBox2.Text;
        else if (sender == textBox3) child03.Text = textBox3.Text;
        // Save text in database here
    }

    private void treeView1_NodeMouseClick(object sender,TreeNodeMouseClickEventArgs e)
    {
        textBox1.Enabled = (e.Node == child01);
        textBox2.Enabled = (e.Node == child02);
        textBox3.Enabled = (e.Node == child03);
    }
}