⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex-14-03

📁 Programming Csharp Source Code(代码) Programming Csharp Source Code
💻
字号:
// Example 14-03: Using a DataGrid Control

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace ProgrammingCSharpWindows.Form
{

   public class ADOForm3 : System.Windows.Forms.Form
   {
      private System.ComponentModel.Container 
         components;
      private System.Windows.Forms.DataGrid 
         CustomerDataGrid;

      public ADOForm3()
      {
         InitializeComponent();

         // set up connection and command strings
         string connectionString = 
            "server=localComputer; uid=sa; pwd=; database=northwind";
         string commandString = 
            "Select CompanyName, ContactName, ContactTitle, "
            + "Phone, Fax from Customers";

         // create a data set and fill it
         SqlDataAdapter DataAdapter = 
            new SqlDataAdapter(commandString, connectionString);
         DataSet DataSet = new DataSet();
         DataAdapter.Fill(DataSet,"Customers");

         // bind the DataSet to the grid
         CustomerDataGrid.DataSource=
            DataSet.Tables["Customers"].DefaultView;           
      }

      public override void Dispose()
      {
         base.Dispose();
         components.Dispose();
      }

      private void InitializeComponent()
      {
         this.components = 
            new System.ComponentModel.Container ();
         this.CustomerDataGrid = 
            new System.Windows.Forms.DataGrid ();
         CustomerDataGrid.BeginInit ();
         CustomerDataGrid.Location = 
            new System.Drawing.Point (8, 24);
         CustomerDataGrid.Size = 
            new System.Drawing.Size (656, 224);
         CustomerDataGrid.DataMember = "";
         CustomerDataGrid.TabIndex = 0;
         CustomerDataGrid.Navigate += 
            new System.Windows.Forms.NavigateEventHandler 
            (this.dataGrid1_Navigate);
         this.Text = "ADOFrm3";
         this.AutoScaleBaseSize = 
            new System.Drawing.Size (5, 13);
         this.ClientSize = new System.Drawing.Size (672, 273);
         this.Controls.Add (this.CustomerDataGrid);
         CustomerDataGrid.EndInit ();
      }

      protected void dataGrid1_Navigate 
         (object sender, System.Windows.Forms.NavigateEventArgs ne)
      {

      }

      public static void Main(string[] args) 
      {
         Application.Run(new ADOForm3());
      }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -