C#目录树的应用

发布时间:2009年06月04日      浏览次数:561 次
目录树控件TreeView是一个很好用的控件,在某些程序上用它,使我们的界面更友好,下面是一个目录树的综合运用的好例子,运行效果很好,下面与大家分享
上图是程序运行的截图.下面是代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace目录树的应用
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void HorizontalSplitContainer_Panel1_Paint(object sender, PaintEventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{
// 声明 Treeview 控件
SalesTreeView.Nodes[0].Expand();
SalesTreeView.Nodes[0].Nodes[0].Expand();
}

private void SalesTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
//
SalesDataGridView.Rows.Clear();
EmployeeTextBox.Text = "";
PhoneTextBox.Text = "";
YTDSalesTextBox.Text = "";

if (e.Node.Text == "李萌" )

{
EmployeeTextBox.Text = e.Node.Text;
PhoneTextBox.Text = "(0851)1234-5678";
YTDSalesTextBox.Text = "$5000,000";

SalesDataGridView.Rows.Add(new Object[] {"4459", "11/22/2007", "$3105.00"});
SalesDataGridView.Rows.Add(new Object[] {"4460", "01/10/2007", "$1895.00"});
EnableControls();
}
else if (e.Node.Text == "花溪区")
{


SalesDataGridView.Rows.Add(new Object[] { "4459", "11/22/2007", "$3105.00" });
SalesDataGridView.Rows.Add(new Object[] { "4460", "01/10/2007", "$1895.00" });
SalesDataGridView.Rows.Add(new Object[] { "3348", "11/15/2007", "$13805.00" });
SalesDataGridView.Rows.Add(new Object[] { "3350", "11/15/2007", "$200000.00" });
EnableControls();

}
else if (e.Node.Text == "周帮新")
{
EmployeeTextBox.Text = e.Node.Text;
PhoneTextBox.Text = "(0851)123-4098";
YTDSalesTextBox.Text = "$213805.00";

SalesDataGridView.Rows.Add(new Object[] { "3348", "11/15/2007", "$13805.00" });
SalesDataGridView.Rows.Add(new Object[] { "3350", "11/15/2007", "$200000.00" });
EnableControls();
}
else if (e.Node.Text == "南明区")
{


SalesDataGridView.Rows.Add(new Object[] { "1128", "10/09/2006", "$4578.00" });
EnableControls();
}

else if (e.Node.Text == "杨品")
{
EmployeeTextBox.Text = e.Node.Text;
PhoneTextBox.Text = "(0851)123-3456";
YTDSalesTextBox.Text = "$4578.00";

SalesDataGridView.Rows.Add(new Object[] { "1128", "10/09/2006", "$4578.00" });
EnableControls();
}
else if (e.Node.Text == "小河区")
{


SalesDataGridView.Rows.Add(new Object[] { "1128", "10/09/2007", "$2984.00" });
EnableControls();
}
else if (e.Node.Text == "何淼")
{
EmployeeTextBox.Text = e.Node.Text;
PhoneTextBox.Text = "(0851)9876-5432";
YTDSalesTextBox.Text = "$2984.00";

SalesDataGridView.Rows.Add(new Object[] { "1128", "10/09/2007", "$2984.00" });
EnableControls();
}
else if (e.Node.Text == "贵阳各区销售额")
{
SalesDataGridView.Rows.Add(new Object[] { "4459", "11/22/2007", "$3105.00" });
SalesDataGridView.Rows.Add(new Object[] { "4460", "01/10/2007", "$1895.00" });
SalesDataGridView.Rows.Add(new Object[] { "3348", "11/15/2007", "$13805.00" });
SalesDataGridView.Rows.Add(new Object[] { "3350", "11/15/2007", "$200000.00" });
SalesDataGridView.Rows.Add(new Object[] { "1128", "10/09/2007", "$2984.00" });
SalesDataGridView.Rows.Add(new Object[] { "1128", "10/09/2007", "$2984.00" });
EnableControls();
}
else
{
EmployeeTextBox.Enabled = false;
PhoneTextBox.Enabled = false;
YTDSalesTextBox.Enabled = false;
SalesDataGridView.Enabled = false;
}


}
private void EnableControls()
{
EmployeeTextBox.Enabled = true;
PhoneTextBox.Enabled = true;
YTDSalesTextBox.Enabled = true;
SalesDataGridView.Enabled = true;
}

}
}
源码下载:
http://dl2.csdn.net/down4/20070921/21174227316.rar
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!