FreeOZ论坛

标题: Using Linq for Master Detail in a DataGridView [打印本页]

作者: xblues    时间: 8-7-2008 04:51
提示: 作者被禁止或删除, 无法发言 标题: Using Linq for Master Detail in a DataGridView
Windows Forms Data Controls and Databinding

Step 1

         Open up Visual Studio 2008 Beta 2 and create a windows forms application

Step 2

         Add a new Linq to Sql classes to the project I named mine Northwind.dbml

Step 3

        I dragged the Northwind databases Orders and Order Details tables on the surface

Step 4

        Save the project and build it

Step 5 这一步是关键

       Open the datasources window and add a new object data source.  Select the Orders table

Step 6

        Drag the orders table on your windows form

Step 7

        Drag the orders_details table on the form

Step 8

        In the form load event add this code
  1. private void Form1_Load(object sender, EventArgs e)
  2. {
  3.         NorthwindDataContext db = new NorthwindDataContext();
  4.         orderBindingSource.DataSource = from o in db.Orders select o;
  5. }
复制代码
原文:
http://forums.microsoft.com/MSDN ... 019272&SiteID=1

这么容易就建立了一个主从表界面,厉害!

[ 本帖最后由 xblues 于 8-7-2008 01:53 编辑 ]




欢迎光临 FreeOZ论坛 (https://www.freeoz.org/bbs/) Powered by Discuz! X3.2