Multiple Data View : DataView « ADO.Net « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » ADO.Net » DataView 
32.41.5.Multiple Data View
using System.Data.SqlClient;
using System.Data;
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

  public class MultipleView : System.Windows.Forms.Form
  {
    private System.Windows.Forms.DataGrid gridArgentina;
    private System.Windows.Forms.DataGrid gridBrazil;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.DataGrid gridAll;

    public MultipleView()
    {
      this.gridArgentina = new System.Windows.Forms.DataGrid();
      this.gridBrazil = new System.Windows.Forms.DataGrid();
      this.label1 = new System.Windows.Forms.Label();
      this.label2 = new System.Windows.Forms.Label();
      this.label3 = new System.Windows.Forms.Label();
      this.gridAll = new System.Windows.Forms.DataGrid();
      ((System.ComponentModel.ISupportInitialize)(this.gridArgentina)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.gridBrazil)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.gridAll)).BeginInit();
      this.SuspendLayout();
      // 
      // gridArgentina
      // 
      this.gridArgentina.DataMember = "";
      this.gridArgentina.Location = new System.Drawing.Point(1232);
      this.gridArgentina.Size = new System.Drawing.Size(41688);
      this.gridArgentina.TabIndex = 0;
      // 
      // gridBrazil
      // 
      this.gridBrazil.DataMember = "";
      this.gridBrazil.Location = new System.Drawing.Point(12156);
      this.gridBrazil.Size = new System.Drawing.Size(41696);
      this.gridBrazil.TabIndex = 1;
      // 
      // label1
      // 
      this.label1.Location = new System.Drawing.Point(1212);
      this.label1.Size = new System.Drawing.Size(15616);
      this.label1.Text = "Customers From Argentina:";
      // 
      // label2
      // 
      this.label2.Location = new System.Drawing.Point(12136);
      this.label2.Size = new System.Drawing.Size(15616);
      this.label2.Text = "Customers From Brazil:";
      // 
      // label3
      // 
      this.label3.Location = new System.Drawing.Point(12268);
      this.label3.Size = new System.Drawing.Size(15616);
      this.label3.Text = "All Customers:";
      // 
      // gridAll
      // 
      this.gridAll.DataMember = "";
      this.gridAll.Location = new System.Drawing.Point(12288);
      this.gridAll.Size = new System.Drawing.Size(41696);
      // 
      // MultipleView
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(514);
      this.ClientSize = new System.Drawing.Size(440398);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.gridAll,
                                      this.label3,
                                      this.label2,
                                      this.label1,
                                      this.gridBrazil,
                                      this.gridArgentina});
      this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.Text = "Multiple Views";
      this.Load += new System.EventHandler(this.MultipleView_Load);
      ((System.ComponentModel.ISupportInitialize)(this.gridArgentina)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.gridBrazil)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.gridAll)).EndInit();
      this.ResumeLayout(false);

    }

    private void MultipleView_Load(object sender, System.EventArgs e)
    {
      string connectionString = "Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI";
      string SQL = "SELECT * FROM Customers";
      SqlConnection con = new SqlConnection(connectionString);
      SqlCommand com = new SqlCommand(SQL, con);
      SqlDataAdapter adapter = new SqlDataAdapter(com);
      DataSet ds = new DataSet("Northwind");      

      con.Open();
      adapter.Fill(ds, "Customers");
      con.Close();

      DataView viewArgentina = new DataView(ds.Tables["Customers"]);
      DataView viewBrazil = new DataView(ds.Tables["Customers"]);

      viewArgentina.RowFilter = "Country = 'Argentina'";
      viewBrazil.RowFilter = "Country = 'Brazil'";

      gridArgentina.DataSource = viewArgentina;
      gridBrazil.DataSource = viewBrazil;
      gridAll.DataSource = ds.Tables["Customers"].DefaultView;    
    }

    [STAThread]
    static void Main() 
    {
      Application.Run(new MultipleView());
    }
  }
32.41.DataView
32.41.1.Attach DataViews to two separate DataGrid controls
32.41.2.DataView Sorter and Filter
32.41.3.Create DataViews from DataTable
32.41.4.Loop through DataRowView in DataView
32.41.5.Multiple Data View
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.