Treeview与外面的文本框

时间:2011-05-25 14:30:42

标签: asp.net c#-3.0

目前我正在研究树视图 除树视图外,还有3个文本框 通过单击treeview的节点,我需要启用文本框 程序是。

  1. 如果我在第一个文本框中写入应显示在treeview的第一个节点的子节点中的文本
  2. 点击该节点,应启用第二个文本框。
  3. 对于应该启用的3个文本框应该相同。
  4. 我在文本框中编写并在节点中复制的文本应保存在数据库中。

1 个答案:

答案 0 :(得分:1)

我假设你的树视图中存在节点 如果不是我的代码给你一些错误。
所有三个文本框OnTextChanged事件都必须引用textBox_TextChanged方法。

响应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);
    }
}