目前我正在研究树视图 除树视图外,还有3个文本框 通过单击treeview的节点,我需要启用文本框 程序是。
答案 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);
}
}