一个关于TreeView的问题?
我在一个窗体(From1)里边拖放了一个treeView1,在另一个窗体(form2)中有个Button1,点击Button1时,在Form1的treeview1上添加一个节点,请问怎么实现?
我的代码: private void button6_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
TreeNode td = new TreeNode();
td.Text = "Hello ";
form1.treeView1.Nodes.Add(td);//添加子点
}
------解决方案--------------------无非 就是窗体之间 互相传值
和 是不是 TreeView 没有关系.我也可以让 窗体2 关闭的时候..窗体1 打印一句话...
授人一鱼.不入授人一渔
==========下面是 2个窗体之间 传值的代码 .研一下.就 会做了..
==============================
namespace ReadFile
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 fm = new Form3();
fm._val = this.textBox1.Text;
if (fm.ShowDialog() == DialogResult.OK)
{
this.textBox1.Text = fm._val;
}
}
}
}
namespace ReadFile
{
public partial class Form3 : Form
{
// 定义一个属性
public string _val;
public string val
{
get
{
return _val;
}
set
{
_val = value;
}
}
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
_val = this.textBox1.Text;
this.DialogResult = DialogResult.OK;
this.Hide();
}
private void Form3_Load(object sender, EventArgs e)
{
this.textBox1.Text = _val;
}
}
}
------解决方案--------------------UP
namespace ReadFile
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 fm = new Form3();
fm._val = this.textBox1.Text;
if (fm.ShowDialog() == DialogResult.OK)
{
this.textBox1.Text = fm._val;
}
}
}
}
namespace ReadFile
{
public partial class Form3 : Form
{
// 定义一个属性
public string _val;
public string val
{
get
{ <