在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → 从数据库读取数据到treeview 示例源码下载

从数据库读取数据到treeview 示例源码下载

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.18M
  • 下载次数:59
  • 浏览次数:637
  • 发布时间:2013-10-03
  • 实例类别:C#语言基础
  • 发 布 人:crazycode
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 数据库 ee

实例介绍

【实例简介】

【实例截图】

【核心代码】

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
using ControlLib;

namespace TestControls
{
	/// <summary>
	/// Summary description for Form2.
	/// </summary>
	public class TestForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panelTop;
		private ControlLib.dbTreeViewCtrl bookTree;
		private System.Windows.Forms.TextBox txtBookID;
		private System.Windows.Forms.Button btnFind;
		private System.Data.DataSet dsBooks;
		private System.Data.DataView bookDataView;
		private System.Data.OleDb.OleDbConnection accessConn;
		private System.Data.OleDb.OleDbCommand cmdGetAuthors;
		private System.Windows.Forms.Splitter splitter2;
		private System.Windows.Forms.Panel panelContainer;
		private System.Windows.Forms.Panel panelPublisher;
		private System.Windows.Forms.TextBox txtPubContry;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox txtPubState;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox txtPubCity;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtPubName;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Panel panelAuthor;
		private System.Windows.Forms.TextBox txtAuthAddress;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.TextBox txtAuthLastName;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.TextBox txtAuthZip;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox txtAuthState;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox txtAuthCity;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TextBox txtAuthFirstName;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Panel panelTitle;
		private System.Windows.Forms.Label lblTitleID;
		private System.Windows.Forms.TextBox txtBookAdvPaid;
		private System.Windows.Forms.TextBox txtBookRoylaty;
		private System.Windows.Forms.TextBox txtBookPrice;
		private System.Windows.Forms.TextBox txtBookYTDSales;
		private System.Windows.Forms.Label label21;
		private System.Windows.Forms.Label label20;
		private System.Windows.Forms.Label label19;
		private System.Windows.Forms.Label label18;
		private System.Windows.Forms.TextBox txtBookTitleNodes;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.TextBox txtBookPubDate;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.TextBox txtBookType;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.TextBox txtBookTitle;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Label label13;
		private ControlLib.dbImageBox imgBookCover;
		private System.Windows.Forms.ImageList imgList;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuPublisher;
		private System.Windows.Forms.MenuItem menuAuthor;
		private System.Windows.Forms.MenuItem menuTitle;
		private System.Windows.Forms.Label lblLocate;
		private System.Windows.Forms.Label lblAuthorID;
		private System.Windows.Forms.Label lblPublisherID;
		private System.ComponentModel.IContainer components;


		public TestForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			this.SetUpDataBinding ();
		}

		/// <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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TestForm));
			this.panelTop = new System.Windows.Forms.Panel();
			this.btnFind = new System.Windows.Forms.Button();
			this.txtBookID = new System.Windows.Forms.TextBox();
			this.lblLocate = new System.Windows.Forms.Label();
			this.bookTree = new ControlLib.dbTreeViewCtrl();
			this.imgList = new System.Windows.Forms.ImageList(this.components);
			this.accessConn = new System.Data.OleDb.OleDbConnection();
			this.dsBooks = new System.Data.DataSet();
			this.bookDataView = new System.Data.DataView();
			this.cmdGetAuthors = new System.Data.OleDb.OleDbCommand();
			this.splitter2 = new System.Windows.Forms.Splitter();
			this.panelContainer = new System.Windows.Forms.Panel();
			this.panelAuthor = new System.Windows.Forms.Panel();
			this.lblAuthorID = new System.Windows.Forms.Label();
			this.txtAuthAddress = new System.Windows.Forms.TextBox();
			this.label12 = new System.Windows.Forms.Label();
			this.txtAuthLastName = new System.Windows.Forms.TextBox();
			this.label11 = new System.Windows.Forms.Label();
			this.txtAuthZip = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.txtAuthState = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.txtAuthCity = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.txtAuthFirstName = new System.Windows.Forms.TextBox();
			this.label9 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.panelPublisher = new System.Windows.Forms.Panel();
			this.lblPublisherID = new System.Windows.Forms.Label();
			this.txtPubContry = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.txtPubState = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.txtPubCity = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.txtPubName = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.panelTitle = new System.Windows.Forms.Panel();
			this.lblTitleID = new System.Windows.Forms.Label();
			this.txtBookTitleNodes = new System.Windows.Forms.TextBox();
			this.imgBookCover = new ControlLib.dbImageBox();
			this.txtBookAdvPaid = new System.Windows.Forms.TextBox();
			this.txtBookRoylaty = new System.Windows.Forms.TextBox();
			this.txtBookPrice = new System.Windows.Forms.TextBox();
			this.txtBookYTDSales = new System.Windows.Forms.TextBox();
			this.label21 = new System.Windows.Forms.Label();
			this.label20 = new System.Windows.Forms.Label();
			this.label19 = new System.Windows.Forms.Label();
			this.label18 = new System.Windows.Forms.Label();
			this.label17 = new System.Windows.Forms.Label();
			this.txtBookPubDate = new System.Windows.Forms.TextBox();
			this.label16 = new System.Windows.Forms.Label();
			this.txtBookType = new System.Windows.Forms.TextBox();
			this.label15 = new System.Windows.Forms.Label();
			this.txtBookTitle = new System.Windows.Forms.TextBox();
			this.label14 = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuPublisher = new System.Windows.Forms.MenuItem();
			this.menuAuthor = new System.Windows.Forms.MenuItem();
			this.menuTitle = new System.Windows.Forms.MenuItem();
			this.panelTop.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dsBooks)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.bookDataView)).BeginInit();
			this.panelContainer.SuspendLayout();
			this.panelAuthor.SuspendLayout();
			this.panelPublisher.SuspendLayout();
			this.panelTitle.SuspendLayout();
			this.SuspendLayout();
			// 
			// panelTop
			// 
			this.panelTop.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(215)), ((System.Byte)(215)), ((System.Byte)(255)));
			this.panelTop.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panelTop.Controls.Add(this.btnFind);
			this.panelTop.Controls.Add(this.txtBookID);
			this.panelTop.Controls.Add(this.lblLocate);
			this.panelTop.Dock = System.Windows.Forms.DockStyle.Top;
			this.panelTop.Location = new System.Drawing.Point(0, 0);
			this.panelTop.Name = "panelTop";
			this.panelTop.Size = new System.Drawing.Size(584, 56);
			this.panelTop.TabIndex = 0;
			// 
			// btnFind
			// 
			this.btnFind.Location = new System.Drawing.Point(384, 16);
			this.btnFind.Name = "btnFind";
			this.btnFind.TabIndex = 2;
			this.btnFind.Text = "Find";
			this.btnFind.Click  = new System.EventHandler(this.btnFind_Click);
			// 
			// txtBookID
			// 
			this.txtBookID.Location = new System.Drawing.Point(272, 16);
			this.txtBookID.Name = "txtBookID";
			this.txtBookID.TabIndex = 1;
			this.txtBookID.Text = "";
			// 
			// lblLocate
			// 
			this.lblLocate.AutoSize = true;
			this.lblLocate.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(177)));
			this.lblLocate.Location = new System.Drawing.Point(48, 16);
			this.lblLocate.Name = "lblLocate";
			this.lblLocate.Size = new System.Drawing.Size(216, 18);
			this.lblLocate.TabIndex = 0;
			this.lblLocate.Text = "Locate Publisher By Publisher ID :";
			this.lblLocate.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// bookTree
			// 
			this.bookTree.AutoBuildTree = true;
			this.bookTree.DataSource = null;
			this.bookTree.DisplayMember = "title";
			this.bookTree.Dock = System.Windows.Forms.DockStyle.Left;
			this.bookTree.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.bookTree.ImageIndex = 2;
			this.bookTree.ImageList = this.imgList;
			this.bookTree.Location = new System.Drawing.Point(0, 56);
			this.bookTree.Name = "bookTree";
			this.bookTree.SelectedImageIndex = 2;
			this.bookTree.Size = new System.Drawing.Size(216, 374);
			this.bookTree.TabIndex = 1;
			this.bookTree.ValueMember = "title_id";
			this.bookTree.AfterSelect  = new System.Windows.Forms.TreeViewEventHandler(this.bookTree_AfterSelect);
			// 
			// imgList
			// 
			this.imgList.ImageSize = new System.Drawing.Size(16, 16);
			this.imgList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgList.ImageStream")));
			this.imgList.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// accessConn
			// 
			this.accessConn.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=""TheSample.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
			// 
			// dsBooks
			// 
			this.dsBooks.DataSetName = "Books";
			this.dsBooks.Locale = new System.Globalization.CultureInfo("en-US");
			// 
			// cmdGetAuthors
			// 
			this.cmdGetAuthors.CommandText = "SELECT GetAuthors.* FROM GetAuthors";
			this.cmdGetAuthors.Connection = this.accessConn;
			// 
			// splitter2
			// 
			this.splitter2.Location = new System.Drawing.Point(216, 56);
			this.splitter2.Name = "splitter2";
			this.splitter2.Size = new System.Drawing.Size(2, 374);
			this.splitter2.TabIndex = 4;
			this.splitter2.TabStop = false;
			// 
			// panelContainer
			// 
			this.panelContainer.Controls.Add(this.panelAuthor);
			this.panelContainer.Controls.Add(this.panelPublisher);
			this.panelContainer.Controls.Add(this.panelTitle);
			this.panelContainer.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panelContainer.Location = new System.Drawing.Point(218, 56);
			this.panelContainer.Name = "panelContainer";
			this.panelContainer.Size = new System.Drawing.Size(366, 374);
			this.panelContainer.TabIndex = 5;
			// 
			// panelAuthor
			// 
			this.panelAuthor.BackColor = System.Drawing.SystemColors.Control;
			this.panelAuthor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panelAuthor.Controls.Add(this.lblAuthorID);
			this.panelAuthor.Controls.Add(this.txtAuthAddress);
			this.panelAuthor.Controls.Add(this.label12);
			this.panelAuthor.Controls.Add(this.txtAuthLastName);
			this.panelAuthor.Controls.Add(this.label11);
			this.panelAuthor.Controls.Add(this.txtAuthZip);
			this.panelAuthor.Controls.Add(this.label6);
			this.panelAuthor.Controls.Add(this.txtAuthState);
			this.panelAuthor.Controls.Add(this.label7);
			this.panelAuthor.Controls.Add(this.txtAuthCity);
			this.panelAuthor.Controls.Add(this.label8);
			this.panelAuthor.Controls.Add(this.txtAuthFirstName);
			this.panelAuthor.Controls.Add(this.label9);
			this.panelAuthor.Controls.Add(this.label10);
			this.panelAuthor.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panelAuthor.Location = new System.Drawing.Point(0, 0);
			this.panelAuthor.Name = "panelAuthor";
			this.panelAuthor.Size = new System.Drawing.Size(366, 374);
			this.panelAuthor.TabIndex = 11;
			// 
			// lblAuthorID
			// 
			this.lblAuthorID.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.lblAuthorID.Location = new System.Drawing.Point(240, 344);
			this.lblAuthorID.Name = "lblAuthorID";
			this.lblAuthorID.Size = new System.Drawing.Size(112, 16);
			this.lblAuthorID.TabIndex = 22;
			this.lblAuthorID.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// txtAuthAddress
			// 
			this.txtAuthAddress.Location = new System.Drawing.Point(112, 152);
			this.txtAuthAddress.Name = "txtAuthAddress";
			this.txtAuthAddress.Size = new System.Drawing.Size(224, 20);
			this.txtAuthAddress.TabIndex = 21;
			this.txtAuthAddress.Text = "";
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(32, 152);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(72, 23);
			this.label12.TabIndex = 20;
			this.label12.Text = "Address:";
			// 
			// txtAuthLastName
			// 
			this.txtAuthLastName.Location = new System.Drawing.Point(112, 96);
			this.txtAuthLastName.Name = "txtAuthLastName";
			this.txtAuthLastName.Size = new System.Drawing.Size(224, 20);
			this.txtAuthLastName.TabIndex = 19;
			this.txtAuthLastName.Text = "";
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(32, 96);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(72, 23);
			this.label11.TabIndex = 18;
			this.label11.Text = "Last Name:";
			// 
			// txtAuthZip
			// 
			this.txtAuthZip.Location = new System.Drawing.Point(112, 248);
			this.txtAuthZip.Name = "txtAuthZip";
			this.txtAuthZip.Size = new System.Drawing.Size(72, 20);
			this.txtAuthZip.TabIndex = 17;
			this.txtAuthZip.Text = "";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(40, 248);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(48, 23);
			this.label6.TabIndex = 16;
			this.label6.Text = "Zip:";
			// 
			// txtAuthState
			// 
			this.txtAuthState.Location = new System.Drawing.Point(112, 216);
			this.txtAuthState.Name = "txtAuthState";
			this.txtAuthState.Size = new System.Drawing.Size(72, 20);
			this.txtAuthState.TabIndex = 15;
			this.txtAuthState.Text = "";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(40, 216);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(48, 23);
			this.label7.TabIndex = 14;
			this.label7.Text = "State:";
			// 
			// txtAuthCity
			// 
			this.txtAuthCity.Location = new System.Drawing.Point(112, 184);
			this.txtAuthCity.Name = "txtAuthCity";
			this.txtAuthCity.Size = new System.Drawing.Size(224, 20);
			this.txtAuthCity.TabIndex = 13;
			this.txtAuthCity.Text = "";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(40, 184);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(48, 23);
			this.label8.TabIndex = 12;
			this.label8.Text = "City:";
			// 
			// txtAuthFirstName
			// 
			this.txtAuthFirstName.Location = new System.Drawing.Point(112, 64);
			this.txtAuthFirstName.Name = "txtAuthFirstName";
			this.txtAuthFirstName.Size = new System.Drawing.Size(224, 20);
			this.txtAuthFirstName.TabIndex = 11;
			this.txtAuthFirstName.Text = "";
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(32, 64);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(72, 23);
			this.label9.TabIndex = 10;
			this.label9.Text = "First Name:";
			// 
			// label10
			// 
			this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label10.Location = new System.Drawing.Point(32, 16);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(168, 23);
			this.label10.TabIndex = 9;
			this.label10.Text = "Author Info";
			// 
			// panelPublisher
			// 
			this.panelPublisher.BackColor = System.Drawing.SystemColors.Control;
			this.panelPublisher.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panelPublisher.Controls.Add(this.lblPublisherID);
			this.panelPublisher.Controls.Add(this.txtPubContry);
			this.panelPublisher.Controls.Add(this.label5);
			this.panelPublisher.Controls.Add(this.txtPubState);
			this.panelPublisher.Controls.Add(this.label4);
			this.panelPublisher.Controls.Add(this.txtPubCity);
			this.panelPublisher.Controls.Add(this.label3);
			this.panelPublisher.Controls.Add(this.txtPubName);
			this.panelPublisher.Controls.Add(this.label2);
			this.panelPublisher.Controls.Add(this.label1);
			this.panelPublisher.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panelPublisher.Location = new System.Drawing.Point(0, 0);
			this.panelPublisher.Name = "panelPublisher";
			this.panelPublisher.Size = new System.Drawing.Size(366, 374);
			this.panelPublisher.TabIndex = 10;
			// 
			// lblPublisherID
			// 
			this.lblPublisherID.Location = new System.Drawing.Point(224, 336);
			this.lblPublisherID.Name = "lblPublisherID";
			this.lblPublisherID.Size = new System.Drawing.Size(120, 24);
			this.lblPublisherID.TabIndex = 9;
			this.lblPublisherID.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtPubContry
			// 
			this.txtPubContry.Location = new System.Drawing.Point(112, 224);
			this.txtPubContry.Name = "txtPubContry";
			this.txtPubContry.Size = new System.Drawing.Size(216, 20);
			this.txtPubContry.TabIndex = 8;
			this.txtPubContry.Text = "";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(40, 224);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(48, 23);
			this.label5.TabIndex = 7;
			this.label5.Text = "Country:";
			// 
			// txtPubState
			// 
			this.txtPubState.Location = new System.Drawing.Point(112, 192);
			this.txtPubState.Name = "txtPubState";
			this.txtPubState.Size = new System.Drawing.Size(216, 20);
			this.txtPubState.TabIndex = 6;
			this.txtPubState.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(40, 192);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(48, 23);
			this.label4.TabIndex = 5;
			this.label4.Text = "State:";
			// 
			// txtPubCity
			// 
			this.txtPubCity.Location = new System.Drawing.Point(112, 160);
			this.txtPubCity.Name = "txtPubCity";
			this.txtPubCity.Size = new System.Drawing.Size(216, 20);
			this.txtPubCity.TabIndex = 4;
			this.txtPubCity.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(40, 160);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(48, 23);
			this.label3.TabIndex = 3;
			this.label3.Text = "City:";
			// 
			// txtPubName
			// 
			this.txtPubName.Location = new System.Drawing.Point(32, 104);
			this.txtPubName.Name = "txtPubName";
			this.txtPubName.Size = new System.Drawing.Size(296, 20);
			this.txtPubName.TabIndex = 2;
			this.txtPubName.Text = "";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(32, 80);
			this.label2.Name = "label2";
			this.label2.TabIndex = 1;
			this.label2.Text = "Publisher Name:";
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(32, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(168, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "Publisher Info";
			// 
			// panelTitle
			// 
			this.panelTitle.BackColor = System.Drawing.SystemColors.Control;
			this.panelTitle.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panelTitle.Controls.Add(this.lblTitleID);
			this.panelTitle.Controls.Add(this.txtBookTitleNodes);
			this.panelTitle.Controls.Add(this.imgBookCover);
			this.panelTitle.Controls.Add(this.txtBookAdvPaid);
			this.panelTitle.Controls.Add(this.txtBookRoylaty);
			this.panelTitle.Controls.Add(this.txtBookPrice);
			this.panelTitle.Controls.Add(this.txtBookYTDSales);
			this.panelTitle.Controls.Add(this.label21);
			this.panelTitle.Controls.Add(this.label20);
			this.panelTitle.Controls.Add(this.label19);
			this.panelTitle.Controls.Add(this.label18);
			this.panelTitle.Controls.Add(this.label17);
			this.panelTitle.Controls.Add(this.txtBookPubDate);
			this.panelTitle.Controls.Add(this.label16);
			this.panelTitle.Controls.Add(this.txtBookType);
			this.panelTitle.Controls.Add(this.label15);
			this.panelTitle.Controls.Add(this.txtBookTitle);
			this.panelTitle.Controls.Add(this.label14);
			this.panelTitle.Controls.Add(this.label13);
			this.panelTitle.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panelTitle.Location = new System.Drawing.Point(0, 0);
			this.panelTitle.Name = "panelTitle";
			this.panelTitle.Size = new System.Drawing.Size(366, 374);
			this.panelTitle.TabIndex = 12;
			// 
			// lblTitleID
			// 
			this.lblTitleID.Location = new System.Drawing.Point(296, 352);
			this.lblTitleID.Name = "lblTitleID";
			this.lblTitleID.Size = new System.Drawing.Size(48, 16);
			this.lblTitleID.TabIndex = 28;
			this.lblTitleID.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// txtBookTitleNodes
			// 
			this.txtBookTitleNodes.Location = new System.Drawing.Point(24, 168);
			this.txtBookTitleNodes.Multiline = true;
			this.txtBookTitleNodes.Name = "txtBookTitleNodes";
			this.txtBookTitleNodes.Size = new System.Drawing.Size(312, 56);
			this.txtBookTitleNodes.TabIndex = 18;
			this.txtBookTitleNodes.Text = "";
			// 
			// imgBookCover
			// 
			this.imgBookCover.ImagePath = null;
			this.imgBookCover.Location = new System.Drawing.Point(40, 248);
			this.imgBookCover.Name = "imgBookCover";
			this.imgBookCover.Size = new System.Drawing.Size(64, 80);
			this.imgBookCover.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.imgBookCover.TabIndex = 30;
			this.imgBookCover.TabStop = false;
			// 
			// txtBookAdvPaid
			// 
			this.txtBookAdvPaid.BackColor = System.Drawing.Color.White;
			this.txtBookAdvPaid.Location = new System.Drawing.Point(240, 312);
			this.txtBookAdvPaid.Name = "txtBookAdvPaid";
			this.txtBookAdvPaid.ReadOnly = true;
			this.txtBookAdvPaid.TabIndex = 26;
			this.txtBookAdvPaid.Text = "";
			this.txtBookAdvPaid.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// txtBookRoylaty
			// 
			this.txtBookRoylaty.Location = new System.Drawing.Point(240, 288);
			this.txtBookRoylaty.Name = "txtBookRoylaty";
			this.txtBookRoylaty.TabIndex = 25;
			this.txtBookRoylaty.Text = "";
			this.txtBookRoylaty.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// txtBookPrice
			// 
			this.txtBookPrice.Location = new System.Drawing.Point(240, 264);
			this.txtBookPrice.Name = "txtBookPrice";
			this.txtBookPrice.TabIndex = 24;
			this.txtBookPrice.Text = "";
			this.txtBookPrice.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// txtBookYTDSales
			// 
			this.txtBookYTDSales.Location = new System.Drawing.Point(240, 240);
			this.txtBookYTDSales.Name = "txtBookYTDSales";
			this.txtBookYTDSales.TabIndex = 23;
			this.txtBookYTDSales.Text = "";
			this.txtBookYTDSales.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// label21
			// 
			this.label21.Location = new System.Drawing.Point(136, 312);
			this.label21.Name = "label21";
			this.label21.TabIndex = 22;
			this.label21.Text = "Advance Paid:";
			// 
			// label20
			// 
			this.label20.Location = new System.Drawing.Point(136, 288);
			this.label20.Name = "label20";
			this.label20.TabIndex = 21;
			this.label20.Text = "Royalty %:";
			// 
			// label19
			// 
			this.label19.Location = new System.Drawing.Point(136, 264);
			this.label19.Name = "label19";
			this.label19.TabIndex = 20;
			this.label19.Text = "Price:";
			// 
			// label18
			// 
			this.label18.Location = new System.Drawing.Point(136, 240);
			this.label18.Name = "label18";
			this.label18.TabIndex = 19;
			this.label18.Text = "YTD Sales";
			// 
			// label17
			// 
			this.label17.Location = new System.Drawing.Point(24, 152);
			this.label17.Name = "label17";
			this.label17.TabIndex = 17;
			this.label17.Text = "Title Nodes:";
			// 
			// txtBookPubDate
			// 
			this.txtBookPubDate.Location = new System.Drawing.Point(120, 120);
			this.txtBookPubDate.Name = "txtBookPubDate";
			this.txtBookPubDate.Size = new System.Drawing.Size(152, 20);
			this.txtBookPubDate.TabIndex = 16;
			this.txtBookPubDate.Text = "";
			// 
			// label16
			// 
			this.label16.Location = new System.Drawing.Point(24, 120);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(88, 23);
			this.label16.TabIndex = 15;
			this.label16.Text = "Publisher Date:";
			// 
			// txtBookType
			// 
			this.txtBookType.Location = new System.Drawing.Point(88, 88);
			this.txtBookType.Name = "txtBookType";
			this.txtBookType.Size = new System.Drawing.Size(184, 20);
			this.txtBookType.TabIndex = 14;
			this.txtBookType.Text = "";
			// 
			// label15
			// 
			this.label15.Location = new System.Drawing.Point(24, 88);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(48, 23);
			this.label15.TabIndex = 13;
			this.label15.Text = "Type:";
			// 
			// txtBookTitle
			// 
			this.txtBookTitle.Location = new System.Drawing.Point(88, 56);
			this.txtBookTitle.Multiline = true;
			this.txtBookTitle.Name = "txtBookTitle";
			this.txtBookTitle.Size = new System.Drawing.Size(248, 20);
			this.txtBookTitle.TabIndex = 12;
			this.txtBookTitle.Text = "";
			// 
			// label14
			// 
			this.label14.Location = new System.Drawing.Point(24, 56);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(56, 23);
			this.label14.TabIndex = 11;
			this.label14.Text = "Title:";
			// 
			// label13
			// 
			this.label13.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label13.Location = new System.Drawing.Point(16, 16);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(168, 23);
			this.label13.TabIndex = 10;
			this.label13.Text = "Book Detail";
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem1});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuPublisher,
																					  this.menuAuthor,
																					  this.menuTitle});
			this.menuItem1.Text = "Add/Remove Group";
			// 
			// menuPublisher
			// 
			this.menuPublisher.Checked = true;
			this.menuPublisher.Index = 0;
			this.menuPublisher.Text = "Publisher";
			this.menuPublisher.Click  = new System.EventHandler(this.menuPublisher_Click);
			// 
			// menuAuthor
			// 
			this.menuAuthor.Checked = true;
			this.menuAuthor.Index = 1;
			this.menuAuthor.Text = "Author";
			this.menuAuthor.Click  = new System.EventHandler(this.menuAuthor_Click);
			// 
			// menuTitle
			// 
			this.menuTitle.Enabled = false;
			this.menuTitle.Index = 2;
			this.menuTitle.Text = "Title";
			this.menuTitle.Click  = new System.EventHandler(this.menuTitle_Click);
			// 
			// TestForm
			// 
			this.AcceptButton = this.btnFind;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(584, 430);
			this.Controls.Add(this.panelContainer);
			this.Controls.Add(this.splitter2);
			this.Controls.Add(this.bookTree);
			this.Controls.Add(this.panelTop);
			this.Menu = this.mainMenu1;
			this.Name = "TestForm";
			this.Tag = "Author";
			this.Text = "Book Browser";
			this.panelTop.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dsBooks)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.bookDataView)).EndInit();
			this.panelContainer.ResumeLayout(false);
			this.panelAuthor.ResumeLayout(false);
			this.panelPublisher.ResumeLayout(false);
			this.panelTitle.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion
		[STAThread]
		static void Main() 
		{
			Application.Run(new TestForm());
		}

		public void SetUpDataBinding()
		{
			int nRows = 0;
			try
			{
				this.accessConn.Open();

				OleDbDataAdapter daAuthors = new OleDbDataAdapter (this.cmdGetAuthors);
				nRows = daAuthors.Fill (this.dsBooks, "Authors");
			}
			catch (System.Data.OleDb.OleDbException e)
			{
				MessageBox.Show (String.Format ("Database Error: {0}", e.Message), "TestControl Application");
			}
			catch ( System.Exception e)
			{
				MessageBox.Show (String.Format ("Error: {0}", e.Message), "TestControl Application");
			}
			this.accessConn.Close();

			this.bookDataView = dsBooks.Tables ["Authors"].DefaultView;
			
			this.bookTree.AutoBuildTree = false;

			this.bookTree.SetLeafData ("Title", "title", "title_id", 2, 2);
			this.bookTree.DataSource = this.bookDataView;
			this.bookTree.AddGroup ("Publisher", "pub_id", "pub_name", "pub_id", 0, 0);
			this.bookTree.AddGroup ("Author", "au_id", "au_name", "au_id", 1, 3);
			this.bookTree.BuildTree();

			if ( this.bookTree.Nodes.Count <= 0 )
				return;

			System.Windows.Forms.Binding myBinding;

			this.txtPubName.DataBindings.Add ("Text", bookDataView, "pub_name");
			this.txtPubCity.DataBindings.Add ("Text", bookDataView, "pub_City");
			this.txtPubState.DataBindings.Add ("Text", bookDataView, "pub_State");
			this.txtPubContry.DataBindings.Add ("Text", bookDataView, "pub_Country");
			this.lblPublisherID.DataBindings.Add ("Text", bookDataView, "pub_id");

			this.txtAuthFirstName.DataBindings.Add ("Text", bookDataView, "au_fname");
			this.txtAuthLastName.DataBindings.Add ("Text", bookDataView, "au_lname");
			this.txtAuthAddress.DataBindings.Add ("Text", bookDataView, "au_address");
			this.txtAuthCity.DataBindings.Add ("Text", bookDataView, "au_city");
			this.txtAuthZip.DataBindings.Add ("Text", bookDataView, "au_zip");
			this.txtAuthState.DataBindings.Add ("Text", bookDataView, "au_state");
			this.lblAuthorID.DataBindings.Add ("Text", bookDataView, "au_id");

			this.txtBookTitle.DataBindings.Add ("Text", bookDataView, "title");
			this.txtBookTitleNodes.DataBindings.Add ("Text", bookDataView, "title_notes");
			this.txtBookType.DataBindings.Add ("Text", bookDataView, "title_type");
			this.txtBookYTDSales.DataBindings.Add  ("Text", bookDataView, "title_ytd_sales");
			this.lblTitleID.DataBindings.Add ("Text", bookDataView, "title_id");
			this.imgBookCover.DataBindings.Add ("ImagePath", bookDataView, "title_imagePath");

			myBinding = this.txtBookPrice.DataBindings.Add ("Text", bookDataView, "title_price");
			myBinding.Format  = new ConvertEventHandler(CurrencyFormat);
			
			myBinding = this.txtBookPubDate.DataBindings.Add ("Text", bookDataView, "title_pubdate");
			myBinding.Format  = new ConvertEventHandler(DateFormat);

			myBinding = this.txtBookRoylaty.DataBindings.Add ("Text", bookDataView, "title_royalty");
			myBinding.Format  = new ConvertEventHandler(PercentFormat);

            myBinding = this.txtBookAdvPaid.DataBindings.Add ("Text", bookDataView, "title_advance");
			myBinding.Format  = new ConvertEventHandler(CurrencyFormat);
				
			String sName = this.bookTree.Tag == null ? "Item" : this.bookTree.Tag.ToString();
			this.lblLocate.Text = "Locate "   sName   " By "   sName   " ID: ";
		}

		public void CurrencyFormat(object sender, ConvertEventArgs e)
		{
			if ( e.Value is System.DBNull ) 
				return;
			
			e.Value = (Convert.ToDouble(e.Value)).ToString ("C");
		}

		public void PercentFormat(object sender, ConvertEventArgs e)
		{
			if ( e.Value is System.DBNull ) 
				return;

			double percentValue = Convert.ToDouble (e.Value);
			percentValue = percentValue / 100;
			e.Value = percentValue.ToString("P0");
		}

		public void DateFormat(object sender, ConvertEventArgs e)
		{
			if ( e.Value is System.DBNull ) 
				return;

			e.Value = Convert.ToDateTime (e.Value).ToShortDateString();
		}

		private void btnFind_Click(object sender, System.EventArgs e)
		{
			if ( this.txtBookTitle.Text.Trim() != String.Empty )
			{
				TreeNode currentNode = this.bookTree.FindNodeByValue (this.txtBookID.Text.ToUpper());

				if ( currentNode != null )
					bookTree.SelectedNode = currentNode;
				else
				{
					this.txtBookID.Focus();
					this.txtBookID.SelectAll();
				}
			}
		}

		private void RebuildTree ()
		{
			String sSort = "";
			int nCheckedCount = 0;
			
			this.bookTree.RemoveAllGroups();

			// set groups and sorting string
			for (int i=0; i<this.menuItem1.MenuItems.Count; i  )
			{
				MenuItem menu = this.menuItem1.MenuItems[i];
				menu.Enabled = true;
				if ( menu.Checked)
				{
					nCheckedCount   ;
					switch (menu.Text)
					{
						case "Publisher" :
							sSort  = "pub_id, ";
							this.bookTree.AddGroup ("Publisher", "pub_id", "pub_name", "pub_id", 0, 0);
							break;
						case "Author" :
							sSort  = "au_name, ";
							this.bookTree.AddGroup ("Author", "au_id", "au_name", "au_id", 1, 3);
							break;
						case "Title" :
							sSort  = "title_id, ";
							this.bookTree.AddGroup ("Title", "title_id", "title", "title_id", 2, 2);
							break;
					}
				}
			}

			// disable the only unchecked menu item to disallow check it.(It, in fact, is a leaf group)
			if ( nCheckedCount == this.menuItem1.MenuItems.Count - 1 )
			{
				for (int i=0; i<this.menuItem1.MenuItems.Count; i  )
					if ( !menuItem1.MenuItems[i].Checked )
						this.menuItem1.MenuItems[i].Enabled = false;
			}
		
			// determine which group is the leaf group and set the leaf data
			if ( sSort.IndexOf ("title_id") < 0 )
				this.bookTree.SetLeafData ("Title", "title", "title_id", 2, 2);
			else if (sSort.IndexOf ("au_name") < 0 )
				this.bookTree.SetLeafData ("Author", "au_name", "au_id", 1, 3);
			else
				this.bookTree.SetLeafData ("Publisher", "pub_name", "pub_id", 0, 0);
			
			// sort and re-build the tree
			this.bookDataView.Sort = sSort   "title_id";
			this.bookTree.BuildTree();

			String sName = this.bookTree.Tag == null ? "Item" : this.bookTree.Tag.ToString();
			this.lblLocate.Text = "Locate "   sName   " By "   sName   " ID: ";
		}
	

		private void menuPublisher_Click(object sender, System.EventArgs e)
		{
			this.menuPublisher.Checked = !this.menuPublisher.Checked;
			this.RebuildTree();
		}

		private void menuAuthor_Click(object sender, System.EventArgs e)
		{
			this.menuAuthor.Checked = !this.menuAuthor.Checked;
			this.RebuildTree();
		}

		private void menuTitle_Click(object sender, System.EventArgs e)
		{
			this.menuTitle.Checked = !this.menuTitle.Checked;
			this.RebuildTree();
		}

		private void bookTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			ControlLib.dbTreeNode node = (ControlLib.dbTreeNode) e.Node;
			
			// determine which page to display
			if ( node != null )
			{
				switch (node.GroupName)
				{
					case "Publisher" :
						this.panelAuthor.Visible = false;
						this.panelTitle.Visible = false;
						this.panelPublisher.Visible = true;
						break;
					case "Author" :
						this.panelPublisher.Visible = false;
						this.panelTitle.Visible = false;
						this.panelAuthor.Visible = true;
						break;
					case "Title" :
						this.panelPublisher.Visible = false;
						this.panelAuthor.Visible = false;
						this.panelTitle.Visible = true;
						break;
				}
				
			}
		}
 	}
}

标签: 数据库 ee

实例下载地址

从数据库读取数据到treeview 示例源码下载

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警