Display Linq result in a DataGridView : DataGridView « LINQ « 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 » LINQ » DataGridView 
22.77.1.Display Linq result in a DataGridView
using System.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

public class Book {
    public String Title get; set; }

    public override String ToString() {
        return Title;
    }
}
public class FormBooks : Form {

    static public Book[] Books =
    {
      new Book {Title="F"},
      new Book {Title="B"}
    };
    public FormBooks() {
        InitializeComponent();
    }

    private void FormStrings_Load(object sender, EventArgs e) {
        String[] books = "F""A""B""R""B" };

        var query =
          from book in books
          where book.Length > 10
          orderby book
          select new Book = book.ToUpper() };

        dataGridView1.DataSource = query.ToList();
    }
    private void InitializeComponent() {
        this.dataGridView1 = new System.Windows.Forms.DataGridView();
        ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
        this.SuspendLayout();
        //
        // dataGridView1
        //
        this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.dataGridView1.Location = new System.Drawing.Point(1010);
        this.dataGridView1.Name = "dataGridView1";
        this.dataGridView1.Size = new System.Drawing.Size(272251);
        this.dataGridView1.TabIndex = 0;
        //
        // FormStrings
        //
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(292271);
        this.Controls.Add(this.dataGridView1);
        this.Name = "FormStrings";
        this.Padding = new System.Windows.Forms.Padding(10);
        this.Text = "FormStrings";
        this.Load += new System.EventHandler(this.FormStrings_Load);
        ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
        this.ResumeLayout(false);

    }
    private System.Windows.Forms.DataGridView dataGridView1;
    public static void Main() {
        Application.Run(new FormBooks());
    }
}
22.77.DataGridView
22.77.1.Display Linq result in a DataGridView
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.