ADO.NET Binding: Master Detail : Data Binding « Database ADO.net « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » Database ADO.net » Data BindingScreenshots 
ADO.NET Binding: Master Detail
ADO.NET Binding: Master Detail

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace ADO.NET_Binding
{
    /// <summary>
    /// Summary description for MasterDetail.
    /// </summary>
    public class MasterDetail : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.Label Label2;
        internal System.Windows.Forms.Label Label1;
        internal System.Windows.Forms.ListBox lstProduct;
        internal System.Windows.Forms.ListBox lstCategory;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

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

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Disposebool disposing )
        {
            ifdisposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Disposedisposing );
        }

        #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.Label2 = new System.Windows.Forms.Label();
            this.Label1 = new System.Windows.Forms.Label();
            this.lstProduct = new System.Windows.Forms.ListBox();
            this.lstCategory = new System.Windows.Forms.ListBox();
            this.SuspendLayout();
            // 
            // Label2
            // 
            this.Label2.Location = new System.Drawing.Point(21213);
            this.Label2.Name = "Label2";
            this.Label2.Size = new System.Drawing.Size(12016);
            this.Label2.TabIndex = 9;
            this.Label2.Text = "Products:";
            // 
            // Label1
            // 
            this.Label1.Location = new System.Drawing.Point(1213);
            this.Label1.Name = "Label1";
            this.Label1.Size = new System.Drawing.Size(12016);
            this.Label1.TabIndex = 8;
            this.Label1.Text = "Categories:";
            // 
            // lstProduct
            // 
            this.lstProduct.Location = new System.Drawing.Point(21229);
            this.lstProduct.Name = "lstProduct";
            this.lstProduct.Size = new System.Drawing.Size(208225);
            this.lstProduct.TabIndex = 7;
            // 
            // lstCategory
            // 
            this.lstCategory.Location = new System.Drawing.Point(1229);
            this.lstCategory.Name = "lstCategory";
            this.lstCategory.Size = new System.Drawing.Size(192225);
            this.lstCategory.TabIndex = 6;
            // 
            // MasterDetail
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(514);
            this.ClientSize = new System.Drawing.Size(432266);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.Label2,
                                                                          this.Label1,
                                                                          this.lstProduct,
                                                                          this.lstCategory});
            this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "MasterDetail";
            this.Text = "MasterDetail";
            this.Load += new System.EventHandler(this.MasterDetail_Load);
            this.ResumeLayout(false);

        }
        #endregion


        private BindingManagerBase categoryBinding;
        private DataSet dsStore = new DataSet();


        private void MasterDetail_Load(object sender, System.EventArgs e)
        {
            dsStore.ReadXmlSchema(Application.StartupPath + "\\store.xsd");
            dsStore.ReadXml(Application.StartupPath + "\\store.xml");
        
            lstCategory.DataSource = dsStore.Tables["Categories"];
            lstCategory.DisplayMember = "CategoryName";

            lstProduct.DataSource = dsStore.Tables["Products"];
            lstProduct.DisplayMember = "ModelName";

            categoryBinding = this.BindingContext[dsStore.Tables["Categories"]];

            categoryBinding.PositionChanged += new EventHandler(Binding_PositionChanged);

            // Invoke method once to update child table at startup.
            Binding_PositionChanged(null,null);
        }

        private void Binding_PositionChanged(object sender, System.EventArgs e)
        {
            string filter;
            DataRow selectedRow;

            // Find the current category row.
            selectedRow = dsStore.Tables["Categories"].Rows[categoryBinding.Position];

            // Create a filter expression using its CategoryID.
            filter = "CategoryID='" + selectedRow["CategoryID"].ToString() "'";

            // Modify the view onto the product table.
            dsStore.Tables["Products"].DefaultView.RowFilter = filter;
        }

        [STAThread]
        static void Main() 
        {
            Application.Run(new MasterDetail());
        }
    }
}



           
       
ADO.NETBinding.zip( 76 k)
Related examples in the same category
1. ADO.NET Binding: Handling ErrorsADO.NET Binding: Handling Errors
2. ADO.NET Binding : Multiple Control BindingADO.NET Binding : Multiple Control Binding
3. ADO.NET Binding : UnsynchronizedADO.NET Binding : Unsynchronized
4. Data Binding 3
5. Data Binding 4
w__w_w__.___j__a___v__a_2_s__.__c_o___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.