Treeview with textboxes outside
Currently I'm working on treeview.
Apart from treeview there are 3 textboxes. By clicking nodes of treeview I need to enable textboxes. Procedure of that is.- If I write text in first text box that should display in treeview's first n开发者_StackOverflow中文版ode's child node
- By clicking that node second text box should be enabled.
- That should be same for 3 textboxes that should be enabled.
- What ever the text that I wrote in textboxes and copied in the node should be saved in database.
I assume that in your treeview nodes are present.
If not my code gives you some error.
All three textboxes OnTextChanged event must reference textBox_TextChanged
method.
RESPONSE 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);
}
}
精彩评论