关于treeview的事件问题 vs2005自带了一个treeview.在主界面,我添加了一个treeview,放在了左边,手动加了一些节点。怎么点击一个父节点下的子节点,右边显示子节点的内容呢?比如,子节点的内容是个winform的界面,怎么把它调出来,显示在主界面的右边呢?在线等~~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 麻烦你们了,尽量说的清楚点,小弟第一次接触treeview这个控件。谢谢先了·· 我也刚接触c#Node.NodeData="aa";用nodedata保存一个标记,当树节点选中后判断当前选中的节点的nodedata里面是不是你允许的值。 子节点的内容是个winform?Node.Tag 里可以放,在TreeView中判断当前点击的是哪个节点,然后使用node.Tag找到保存的内容。 比如A下包括a,b,点a,右边出现a的内容。a的内容也是个winform界面的,可以给出代码吗? //一个小例子,有bug,仅供参考//第一次好使,关掉窗体后,就会出错using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace FormMdi{ /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TreeView treeView1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // //为子节点添加窗体 foreach(TreeNode node in this.treeView1.Nodes) { if (node.Nodes.Count>0) { foreach(TreeNode childNode in node.Nodes) { Form fm = new Form(); fm.Text = childNode.Text; childNode.Tag = fm; } } } } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.treeView1 = new System.Windows.Forms.TreeView(); this.SuspendLayout(); // // treeView1 // this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.treeView1.ImageIndex = -1; this.treeView1.Location = new System.Drawing.Point(-8, 0); this.treeView1.Name = "treeView1"; this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] { new System.Windows.Forms.TreeNode("A", new System.Windows.Forms.TreeNode[] { new System.Windows.Forms.TreeNode("a"), new System.Windows.Forms.TreeNode("b")})}); this.treeView1.SelectedImageIndex = -1; this.treeView1.Size = new System.Drawing.Size(144, 344); this.treeView1.TabIndex = 1; this.treeView1.DoubleClick += new System.EventHandler(this.treeView1_DoubleClick); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(536, 342); this.Controls.Add(this.treeView1); this.IsMdiContainer = true; this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void treeView1_DoubleClick(object sender, System.EventArgs e) { if (this.treeView1.SelectedNode!=null) { //如果Tag不为空,就把其中保存的窗体显示出来。 //此代码为参考用,有太多的bug了。 if (this.treeView1.SelectedNode.Tag!=null) { Form fm = (Form)(this.treeView1.SelectedNode.Tag); fm.MdiParent = this; fm.Show(); } } } }} 如何获取USB接口打印机的设备范例Id ? C#开发,VS2005时常用什么构架? C/S结构的上传下载 CS高手进,真心求教 求修改一个正则表达式! 比较初级的问题 C#如何不使用WebBrowser类获取网页框架。 从一个dataSet向另一个dataSet传值 怎样使用C#编写程序下载ftp服务器的文件 如何实现获取在win98下消息框,返回值,那位高手给解答一下。 关于C#使用MQ,添加引用时应该添加那个项阿 用c#做directx开发是不是一定要安装dx产生dll?
Node.NodeData="aa";
用nodedata保存一个标记,当树节点选中后判断当前选中的节点的nodedata里面是不是你允许的值。
//第一次好使,关掉窗体后,就会出错using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace FormMdi
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView treeView1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
//为子节点添加窗体
foreach(TreeNode node in this.treeView1.Nodes)
{
if (node.Nodes.Count>0)
{
foreach(TreeNode childNode in node.Nodes)
{
Form fm = new Form();
fm.Text = childNode.Text;
childNode.Tag = fm;
}
}
}
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.treeView1.ImageIndex = -1;
this.treeView1.Location = new System.Drawing.Point(-8, 0);
this.treeView1.Name = "treeView1";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("A", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("a"),
new System.Windows.Forms.TreeNode("b")})});
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(144, 344);
this.treeView1.TabIndex = 1;
this.treeView1.DoubleClick += new System.EventHandler(this.treeView1_DoubleClick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(536, 342);
this.Controls.Add(this.treeView1);
this.IsMdiContainer = true;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void treeView1_DoubleClick(object sender, System.EventArgs e)
{
if (this.treeView1.SelectedNode!=null)
{
//如果Tag不为空,就把其中保存的窗体显示出来。
//此代码为参考用,有太多的bug了。
if (this.treeView1.SelectedNode.Tag!=null)
{
Form fm = (Form)(this.treeView1.SelectedNode.Tag);
fm.MdiParent = this;
fm.Show();
}
}
}
}
}