DataView Sorter and Filter : 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# / CSharp Tutorial » ADO.Net » DataView 
32.41.2.DataView Sorter and Filter
using System;        
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;

public class DataViewManagerDemo : System.Windows.Forms.Form
{
  private System.Windows.Forms.DataGrid dataGrid1;

  public DataViewManagerDemo()
  {
    InitializeComponent();
  }

  private void InitializeComponent()
  {
    this.dataGrid1 = new System.Windows.Forms.DataGrid();
    ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
    this.SuspendLayout();
    // 
    this.dataGrid1.DataMember = "";
    this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
    this.dataGrid1.Location = new System.Drawing.Point(88);
    this.dataGrid1.Size = new System.Drawing.Size(448328);
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(513);
    this.ClientSize = new System.Drawing.Size(480341);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                    this.dataGrid1});
    this.Load += new System.EventHandler(this.DataViewManagerDemo_Load);
    ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
    this.ResumeLayout(false);

  }

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

  private void DataViewManagerDemo_Load(object sender, System.EventArgs e)
    {
        string ConnectionString ="Integrated Security=SSPI;Initial Catalog=Northwind;Data Source=localhost;";
        SqlConnection conn = new SqlConnection(ConnectionString);

        conn.Open();

        DataSet ds = new DataSet("Orders");

        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Orders", conn);

        adapter.Fill(ds, "Orders");

        DataViewManager dvm = new DataViewManager(ds);

        dvm.DataViewSettings["Orders"].RowFilter = "EmployeeID = 4";
        dvm.DataViewSettings["Orders"].Sort = "ShippedDate ASC";

        DataView dataView1 = dvm.CreateDataView(ds.Tables["Orders"]);

        dataGrid1.DataSource = dataView1;
    }
}
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.