DataGrid 類別

定義

在可捲動方格中顯示 ADO.NET 資料。

此類別在 .NET Core 3.1 和更新版本中無法使用。 請改用 DataGridView 控制項,以取代和擴充 DataGrid 控制項。

public ref class DataGrid : System::Windows::Forms::Control, System::ComponentModel::ISupportInitialize, System::Windows::Forms::IDataGridEditingService
public class DataGrid : System.Windows.Forms.Control, System.ComponentModel.ISupportInitialize, System.Windows.Forms.IDataGridEditingService
[System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
public class DataGrid : System.Windows.Forms.Control, System.ComponentModel.ISupportInitialize, System.Windows.Forms.IDataGridEditingService
type DataGrid = class
    inherit Control
    interface ISupportInitialize
    interface IDataGridEditingService
[<System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")>]
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type DataGrid = class
    inherit Control
    interface ISupportInitialize
    interface IDataGridEditingService
Public Class DataGrid
Inherits Control
Implements IDataGridEditingService, ISupportInitialize
繼承
屬性
實作

範例

下列程式碼範例會建立 Windows 表單、 DataSet 包含兩 DataTable 個 物件的 ,以及 DataRelation 與兩個數據表相關的 。 若要顯示資料, System.Windows.Forms.DataGrid 控制項接著會透過 SetDataBinding 方法系結至 DataSet 。 表單上的按鈕會藉由建立兩 DataGridTableStyle 個 物件並將每個物件的 設定 MappingNameTableName 其中一個 DataTable 物件的 ,來變更格線的外觀。 此範例也包含 事件中的 MouseUp 程式碼,該事件會使用 HitTest 方法來列印已按一下之方格的資料行、列和部分。

#using <system.dll>
#using <system.data.dll>
#using <system.drawing.dll>
#using <system.windows.forms.dll>
#using <system.xml.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Windows::Forms;

#define null 0
public ref class Form1: public System::Windows::Forms::Form
{
private:
   System::ComponentModel::Container^ components;
   Button^ button1;
   Button^ button2;
   DataGrid^ myDataGrid;
   DataSet^ myDataSet;
   bool TablesAlreadyAdded;

public:
   Form1()
   {
      // Required for Windows Form Designer support.
      InitializeComponent();

      // Call SetUp to bind the controls.
      SetUp();
   }

public:
   ~Form1()
   {
      if ( components != nullptr )
      {
         delete components;
      }
   }

private:
   void InitializeComponent()
   {
      // Create the form and its controls.
      this->components = gcnew System::ComponentModel::Container;
      this->button1 = gcnew System::Windows::Forms::Button;
      this->button2 = gcnew System::Windows::Forms::Button;
      this->myDataGrid = gcnew DataGrid;
      this->Text = "DataGrid Control Sample";
      this->ClientSize = System::Drawing::Size( 450, 330 );
      button1->Location = System::Drawing::Point( 24, 16 );
      button1->Size = System::Drawing::Size( 120, 24 );
      button1->Text = "Change Appearance";
      button1->Click += gcnew System::EventHandler( this, &Form1::button1_Click );
      button2->Location = System::Drawing::Point( 150, 16 );
      button2->Size = System::Drawing::Size( 120, 24 );
      button2->Text = "Get Binding Manager";
      button2->Click += gcnew System::EventHandler( this, &Form1::button2_Click );
      myDataGrid->Location = System::Drawing::Point( 24, 50 );
      myDataGrid->Size = System::Drawing::Size( 300, 200 );
      myDataGrid->CaptionText = "Microsoft DataGrid Control";
      myDataGrid->MouseUp += gcnew MouseEventHandler( this, &Form1::Grid_MouseUp );
      this->Controls->Add( button1 );
      this->Controls->Add( button2 );
      this->Controls->Add( myDataGrid );
   }

   void SetUp()
   {
      // Create a DataSet with two tables and one relation.
      MakeDataSet();

      /* Bind the DataGrid to the DataSet. The dataMember
        specifies that the Customers table should be displayed.*/
      myDataGrid->SetDataBinding( myDataSet, "Customers" );
   }

private:
   void button1_Click( Object^ sender, System::EventArgs^ e )
   {
      if ( TablesAlreadyAdded )
            return;

      AddCustomDataTableStyle();
   }

private:
   void AddCustomDataTableStyle()
   {
      DataGridTableStyle^ ts1 = gcnew DataGridTableStyle;
      ts1->MappingName = "Customers";

      // Set other properties.
      ts1->AlternatingBackColor = Color::LightGray;

      /* Add a GridColumnStyle and set its MappingName 
        to the name of a DataColumn in the DataTable. 
        Set the HeaderText and Width properties. */
      DataGridColumnStyle^ boolCol = gcnew DataGridBoolColumn;
      boolCol->MappingName = "Current";
      boolCol->HeaderText = "IsCurrent Customer";
      boolCol->Width = 150;
      ts1->GridColumnStyles->Add( boolCol );

      // Add a second column style.
      DataGridColumnStyle^ TextCol = gcnew DataGridTextBoxColumn;
      TextCol->MappingName = "custName";
      TextCol->HeaderText = "Customer Name";
      TextCol->Width = 250;
      ts1->GridColumnStyles->Add( TextCol );

      // Create the second table style with columns.
      DataGridTableStyle^ ts2 = gcnew DataGridTableStyle;
      ts2->MappingName = "Orders";

      // Set other properties.
      ts2->AlternatingBackColor = Color::LightBlue;

      // Create new ColumnStyle objects
      DataGridColumnStyle^ cOrderDate = gcnew DataGridTextBoxColumn;
      cOrderDate->MappingName = "OrderDate";
      cOrderDate->HeaderText = "Order Date";
      cOrderDate->Width = 100;
      ts2->GridColumnStyles->Add( cOrderDate );

      /* Use a PropertyDescriptor to create a formatted
        column. First get the PropertyDescriptorCollection
        for the data source and data member. */
      PropertyDescriptorCollection^ pcol = this->BindingContext[myDataSet, "Customers.custToOrders"]->GetItemProperties();

      /* Create a formatted column using a PropertyDescriptor.
        The formatting character "c" specifies a currency format. */
      DataGridColumnStyle^ csOrderAmount = gcnew DataGridTextBoxColumn( pcol[ "OrderAmount" ],"c",true );
      csOrderAmount->MappingName = "OrderAmount";
      csOrderAmount->HeaderText = "Total";
      csOrderAmount->Width = 100;
      ts2->GridColumnStyles->Add( csOrderAmount );

      /* Add the DataGridTableStyle instances to 
        the GridTableStylesCollection. */
      myDataGrid->TableStyles->Add( ts1 );
      myDataGrid->TableStyles->Add( ts2 );

      // Sets the TablesAlreadyAdded to true so this doesn't happen again.
      TablesAlreadyAdded = true;
   }

private:
   void button2_Click( Object^ sender, System::EventArgs^ e )
   {
      BindingManagerBase^ bmGrid;
      bmGrid = BindingContext[myDataSet, "Customers"];
      MessageBox::Show( String::Concat( "Current BindingManager Position: ", bmGrid->Position )->ToString() );
   }

private:
   void Grid_MouseUp( Object^ sender, MouseEventArgs^ e )
   {
      // Create a HitTestInfo object using the HitTest method.
      // Get the DataGrid by casting sender.
      DataGrid^ myGrid = dynamic_cast<DataGrid^>(sender);
      DataGrid::HitTestInfo ^ myHitInfo = myGrid->HitTest( e->X, e->Y );
      Console::WriteLine( myHitInfo );
      Console::WriteLine( myHitInfo->Type );
      Console::WriteLine( myHitInfo->Row );
      Console::WriteLine( myHitInfo->Column );
   }

   // Create a DataSet with two tables and populate it.
   void MakeDataSet()
   {
      // Create a DataSet.
      myDataSet = gcnew DataSet( "myDataSet" );

      // Create two DataTables.
      DataTable^ tCust = gcnew DataTable( "Customers" );
      DataTable^ tOrders = gcnew DataTable( "Orders" );

      // Create two columns, and add them to the first table.
      DataColumn^ cCustID = gcnew DataColumn( "CustID",__int32::typeid );
      DataColumn^ cCustName = gcnew DataColumn( "CustName" );
      DataColumn^ cCurrent = gcnew DataColumn( "Current",bool::typeid );
      tCust->Columns->Add( cCustID );
      tCust->Columns->Add( cCustName );
      tCust->Columns->Add( cCurrent );

      // Create three columns, and add them to the second table.
      DataColumn^ cID = gcnew DataColumn( "CustID",__int32::typeid );
      DataColumn^ cOrderDate = gcnew DataColumn( "orderDate",DateTime::typeid );
      DataColumn^ cOrderAmount = gcnew DataColumn( "OrderAmount",Decimal::typeid );
      tOrders->Columns->Add( cOrderAmount );
      tOrders->Columns->Add( cID );
      tOrders->Columns->Add( cOrderDate );

      // Add the tables to the DataSet.
      myDataSet->Tables->Add( tCust );
      myDataSet->Tables->Add( tOrders );

      // Create a DataRelation, and add it to the DataSet.
      DataRelation^ dr = gcnew DataRelation( "custToOrders",cCustID,cID );
      myDataSet->Relations->Add( dr );

      /* Populate the tables. For each customer and order, 
        create need two DataRow variables. */
      DataRow^ newRow1;
      DataRow^ newRow2;

      // Create three customers in the Customers Table.
      for ( int i = 1; i < 4; i++ )
      {
         newRow1 = tCust->NewRow();
         newRow1[ "custID" ] = i;
         
         // Add the row to the Customers table.
         tCust->Rows->Add( newRow1 );
      }
      tCust->Rows[ 0 ][ "custName" ] = "Customer1";
      tCust->Rows[ 1 ][ "custName" ] = "Customer2";
      tCust->Rows[ 2 ][ "custName" ] = "Customer3";

      // Give the Current column a value.
      tCust->Rows[ 0 ][ "Current" ] = true;
      tCust->Rows[ 1 ][ "Current" ] = true;
      tCust->Rows[ 2 ][ "Current" ] = false;

      // For each customer, create five rows in the Orders table.
      for ( int i = 1; i < 4; i++ )
      {
         for ( int j = 1; j < 6; j++ )
         {
            newRow2 = tOrders->NewRow();
            newRow2[ "CustID" ] = i;
            newRow2[ "orderDate" ] = DateTime(2001,i,j * 2);
            newRow2[ "OrderAmount" ] = i * 10 + j * .1;
            
            // Add the row to the Orders table.
            tOrders->Rows->Add( newRow2 );
         }
      }
   }
};

int main()
{
   Application::Run( gcnew Form1 );
}
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
{
   private System.ComponentModel.Container components;
   private Button button1;
   private Button button2;
   private DataGrid myDataGrid;   
   private DataSet myDataSet;
   private bool TablesAlreadyAdded;
   public Form1()
   {
      // Required for Windows Form Designer support.
      InitializeComponent();
      // Call SetUp to bind the controls.
      SetUp();
   }

   protected override void Dispose( bool disposing ){
      if( disposing ){
         if (components != null){
            components.Dispose();}
      }
      base.Dispose( disposing );
   }
   private void InitializeComponent()
   {
      // Create the form and its controls.
      this.components = new System.ComponentModel.Container();
      this.button1 = new System.Windows.Forms.Button();
      this.button2 = new System.Windows.Forms.Button();
      this.myDataGrid = new DataGrid();
      
      this.Text = "DataGrid Control Sample";
      this.ClientSize = new System.Drawing.Size(450, 330);
      
      button1.Location = new Point(24, 16);
      button1.Size = new System.Drawing.Size(120, 24);
      button1.Text = "Change Appearance";
      button1.Click+=new System.EventHandler(button1_Click);

      button2.Location = new Point(150, 16);
      button2.Size = new System.Drawing.Size(120, 24);
      button2.Text = "Get Binding Manager";
      button2.Click+=new System.EventHandler(button2_Click);

      myDataGrid.Location = new  Point(24, 50);
      myDataGrid.Size = new Size(300, 200);
      myDataGrid.CaptionText = "Microsoft DataGrid Control";
      myDataGrid.MouseUp += new MouseEventHandler(Grid_MouseUp);
      
      this.Controls.Add(button1);
      this.Controls.Add(button2);
      this.Controls.Add(myDataGrid);
   }

   public static void Main()
   {
      Application.Run(new Form1());
   }
   
   private void SetUp()
   {
      // Create a DataSet with two tables and one relation.
      MakeDataSet();
      /* Bind the DataGrid to the DataSet. The dataMember
      specifies that the Customers table should be displayed.*/
      myDataGrid.SetDataBinding(myDataSet, "Customers");
   }

   private void button1_Click(object sender, System.EventArgs e)
   {
      if(TablesAlreadyAdded) return;
      AddCustomDataTableStyle();
   }

   private void AddCustomDataTableStyle()
   {
      DataGridTableStyle ts1 = new DataGridTableStyle();
      ts1.MappingName = "Customers";
      // Set other properties.
      ts1.AlternatingBackColor = Color.LightGray;

      /* Add a GridColumnStyle and set its MappingName 
      to the name of a DataColumn in the DataTable. 
      Set the HeaderText and Width properties. */
      
      DataGridColumnStyle boolCol = new DataGridBoolColumn();
      boolCol.MappingName = "Current";
      boolCol.HeaderText = "IsCurrent Customer";
      boolCol.Width = 150;
      ts1.GridColumnStyles.Add(boolCol);
      
      // Add a second column style.
      DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
      TextCol.MappingName = "custName";
      TextCol.HeaderText = "Customer Name";
      TextCol.Width = 250;
      ts1.GridColumnStyles.Add(TextCol);

      // Create the second table style with columns.
      DataGridTableStyle ts2 = new DataGridTableStyle();
      ts2.MappingName = "Orders";

      // Set other properties.
      ts2.AlternatingBackColor = Color.LightBlue;
      
      // Create new ColumnStyle objects
      DataGridColumnStyle cOrderDate = 
      new DataGridTextBoxColumn();
      cOrderDate.MappingName = "OrderDate";
      cOrderDate.HeaderText = "Order Date";
      cOrderDate.Width = 100;
      ts2.GridColumnStyles.Add(cOrderDate);

      /* Use a PropertyDescriptor to create a formatted
      column. First get the PropertyDescriptorCollection
      for the data source and data member. */
      PropertyDescriptorCollection pcol = this.BindingContext
      [myDataSet, "Customers.custToOrders"].GetItemProperties();
 
      /* Create a formatted column using a PropertyDescriptor.
      The formatting character "c" specifies a currency format. */     
      DataGridColumnStyle csOrderAmount = 
      new DataGridTextBoxColumn(pcol["OrderAmount"], "c", true);
      csOrderAmount.MappingName = "OrderAmount";
      csOrderAmount.HeaderText = "Total";
      csOrderAmount.Width = 100;
      ts2.GridColumnStyles.Add(csOrderAmount);

      /* Add the DataGridTableStyle instances to 
      the GridTableStylesCollection. */
      myDataGrid.TableStyles.Add(ts1);
      myDataGrid.TableStyles.Add(ts2);

     // Sets the TablesAlreadyAdded to true so this doesn't happen again.
     TablesAlreadyAdded=true;
   }

   private void button2_Click(object sender, System.EventArgs e)
   {
      BindingManagerBase bmGrid;
      bmGrid = BindingContext[myDataSet, "Customers"];
      MessageBox.Show("Current BindingManager Position: " + bmGrid.Position);
   }

   private void Grid_MouseUp(object sender, MouseEventArgs e)
   {
      // Create a HitTestInfo object using the HitTest method.

      // Get the DataGrid by casting sender.
      DataGrid myGrid = (DataGrid)sender;
      DataGrid.HitTestInfo myHitInfo = myGrid.HitTest(e.X, e.Y);
      Console.WriteLine(myHitInfo);
      Console.WriteLine(myHitInfo.Type);
      Console.WriteLine(myHitInfo.Row);
      Console.WriteLine(myHitInfo.Column);
   }

   // Create a DataSet with two tables and populate it.
   private void MakeDataSet()
   {
      // Create a DataSet.
      myDataSet = new DataSet("myDataSet");
      
      // Create two DataTables.
      DataTable tCust = new DataTable("Customers");
      DataTable tOrders = new DataTable("Orders");

      // Create two columns, and add them to the first table.
      DataColumn cCustID = new DataColumn("CustID", typeof(int));
      DataColumn cCustName = new DataColumn("CustName");
      DataColumn cCurrent = new DataColumn("Current", typeof(bool));
      tCust.Columns.Add(cCustID);
      tCust.Columns.Add(cCustName);
      tCust.Columns.Add(cCurrent);

      // Create three columns, and add them to the second table.
      DataColumn cID = 
      new DataColumn("CustID", typeof(int));
      DataColumn cOrderDate = 
      new DataColumn("orderDate",typeof(DateTime));
      DataColumn cOrderAmount = 
      new DataColumn("OrderAmount", typeof(decimal));
      tOrders.Columns.Add(cOrderAmount);
      tOrders.Columns.Add(cID);
      tOrders.Columns.Add(cOrderDate);

      // Add the tables to the DataSet.
      myDataSet.Tables.Add(tCust);
      myDataSet.Tables.Add(tOrders);

      // Create a DataRelation, and add it to the DataSet.
      DataRelation dr = new DataRelation
      ("custToOrders", cCustID , cID);
      myDataSet.Relations.Add(dr);
   
      /* Populates the tables. For each customer and order, 
      creates two DataRow variables. */
      DataRow newRow1;
      DataRow newRow2;

      // Create three customers in the Customers Table.
      for(int i = 1; i < 4; i++)
      {
         newRow1 = tCust.NewRow();
         newRow1["custID"] = i;
         // Add the row to the Customers table.
         tCust.Rows.Add(newRow1);
      }
      // Give each customer a distinct name.
      tCust.Rows[0]["custName"] = "Customer1";
      tCust.Rows[1]["custName"] = "Customer2";
      tCust.Rows[2]["custName"] = "Customer3";

      // Give the Current column a value.
      tCust.Rows[0]["Current"] = true;
      tCust.Rows[1]["Current"] = true;
      tCust.Rows[2]["Current"] = false;

      // For each customer, create five rows in the Orders table.
      for(int i = 1; i < 4; i++)
      {
         for(int j = 1; j < 6; j++)
         {
            newRow2 = tOrders.NewRow();
            newRow2["CustID"]= i;
            newRow2["orderDate"]= new DateTime(2001, i, j * 2);
            newRow2["OrderAmount"] = i * 10 + j  * .1;
            // Add the row to the Orders table.
            tOrders.Rows.Add(newRow2);
         }
      }
   }
}
Option Explicit
Option Strict

Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
   Inherits System.Windows.Forms.Form
   Private components As System.ComponentModel.Container
   Private button1 As Button
   Private button2 As Button
   Private myDataGrid As DataGrid
   Private myDataSet As DataSet
   Private TablesAlreadyAdded As Boolean    
    
   Public Sub New()
      ' Required for Windows Form Designer support.
      InitializeComponent()
      ' Call SetUp to bind the controls.
      SetUp()
   End Sub 
        
  Private Sub InitializeComponent()
      ' Create the form and its controls.
      Me.components = New System.ComponentModel.Container()
      Me.button1 = New System.Windows.Forms.Button()
      Me.button2 = New System.Windows.Forms.Button()
      Me.myDataGrid = New DataGrid()
      
      Me.Text = "DataGrid Control Sample"
      Me.ClientSize = New System.Drawing.Size(450, 330)
        
      button1.Location = New Point(24, 16)
      button1.Size = New System.Drawing.Size(120, 24)
      button1.Text = "Change Appearance"
      AddHandler button1.Click, AddressOf button1_Click
        
      button2.Location = New Point(150, 16)
      button2.Size = New System.Drawing.Size(120, 24)
      button2.Text = "Get Binding Manager"
      AddHandler button2.Click, AddressOf button2_Click
        
      myDataGrid.Location = New Point(24, 50)
      myDataGrid.Size = New Size(300, 200)
      myDataGrid.CaptionText = "Microsoft DataGrid Control"
      AddHandler myDataGrid.MouseUp, AddressOf Grid_MouseUp
        
      Me.Controls.Add(button1)
      Me.Controls.Add(button2)
      Me.Controls.Add(myDataGrid)
   End Sub 
    
   Public Shared Sub Main()
      Application.Run(New Form1())
   End Sub 
        
   Private Sub SetUp()
      ' Create a DataSet with two tables and one relation.
      MakeDataSet()
      ' Bind the DataGrid to the DataSet. The dataMember
      ' specifies that the Customers table should be displayed.
      myDataGrid.SetDataBinding(myDataSet, "Customers")
   End Sub 
        
    Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If TablesAlreadyAdded = True Then Exit Sub
        AddCustomDataTableStyle()
    End Sub
   
   Private Sub AddCustomDataTableStyle()
      Dim ts1 As New DataGridTableStyle()
      ts1.MappingName = "Customers"
      ' Set other properties.
      ts1.AlternatingBackColor = Color.LightGray
      ' Add a GridColumnStyle and set its MappingName 
      ' to the name of a DataColumn in the DataTable. 
      ' Set the HeaderText and Width properties. 
        
      Dim boolCol As New DataGridBoolColumn()
      boolCol.MappingName = "Current"
      boolCol.HeaderText = "IsCurrent Customer"
      boolCol.Width = 150
      ts1.GridColumnStyles.Add(boolCol)
        
      ' Add a second column style.
      Dim TextCol As New DataGridTextBoxColumn()
      TextCol.MappingName = "custName"
      TextCol.HeaderText = "Customer Name"
      TextCol.Width = 250
      ts1.GridColumnStyles.Add(TextCol)
        
      ' Create the second table style with columns.
      Dim ts2 As New DataGridTableStyle()
      ts2.MappingName = "Orders"
        
      ' Set other properties.
      ts2.AlternatingBackColor = Color.LightBlue
        
      ' Create new ColumnStyle objects
      Dim cOrderDate As New DataGridTextBoxColumn()
      cOrderDate.MappingName = "OrderDate"
      cOrderDate.HeaderText = "Order Date"
      cOrderDate.Width = 100
      ts2.GridColumnStyles.Add(cOrderDate)

      ' Use a PropertyDescriptor to create a formatted
      ' column. First get the PropertyDescriptorCollection
      ' for the data source and data member. 
      Dim pcol As PropertyDescriptorCollection = _
      Me.BindingContext(myDataSet, "Customers.custToOrders"). _
      GetItemProperties()

      ' Create a formatted column using a PropertyDescriptor.
      ' The formatting character "c" specifies a currency format. */     
        
      Dim csOrderAmount As _
      New DataGridTextBoxColumn(pcol("OrderAmount"), "c", True)
      csOrderAmount.MappingName = "OrderAmount"
      csOrderAmount.HeaderText = "Total"
      csOrderAmount.Width = 100
      ts2.GridColumnStyles.Add(csOrderAmount)
        
      ' Add the DataGridTableStyle instances to 
      ' the GridTableStylesCollection. 
      myDataGrid.TableStyles.Add(ts1)
      myDataGrid.TableStyles.Add(ts2)

     ' Sets the TablesAlreadyAdded to true so this doesn't happen again.
      TablesAlreadyAdded = true
   End Sub 
    
    Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim bmGrid As BindingManagerBase
        bmGrid = BindingContext(myDataSet, "Customers")
        MessageBox.Show(("Current BindingManager Position: " & bmGrid.Position))
    End Sub
        
   Private Sub Grid_MouseUp(sender As Object, e As MouseEventArgs)
      ' Create a HitTestInfo object using the HitTest method.
      ' Get the DataGrid by casting sender.
      Dim myGrid As DataGrid = CType(sender, DataGrid)
      Dim myHitInfo As DataGrid.HitTestInfo = myGrid.HitTest(e.X, e.Y)
      Console.WriteLine(myHitInfo)
      Console.WriteLine(myHitInfo.Type)
      Console.WriteLine(myHitInfo.Row)
      Console.WriteLine(myHitInfo.Column)
   End Sub 
        
   ' Create a DataSet with two tables and populate it.
   Private Sub MakeDataSet()
      ' Create a DataSet.
      myDataSet = New DataSet("myDataSet")
       
      ' Create two DataTables.
      Dim tCust As New DataTable("Customers")
      Dim tOrders As New DataTable("Orders")
      
      ' Create two columns, and add them to the first table.
      Dim cCustID As New DataColumn("CustID", GetType(Integer))
      Dim cCustName As New DataColumn("CustName")
      Dim cCurrent As New DataColumn("Current", GetType(Boolean))
      tCust.Columns.Add(cCustID)
      tCust.Columns.Add(cCustName)
      tCust.Columns.Add(cCurrent)
       
      ' Create three columns, and add them to the second table.
      Dim cID As New DataColumn("CustID", GetType(Integer))
      Dim cOrderDate As New DataColumn("orderDate", GetType(DateTime))
      Dim cOrderAmount As New DataColumn("OrderAmount", GetType(Decimal))
      tOrders.Columns.Add(cOrderAmount)
      tOrders.Columns.Add(cID)
      tOrders.Columns.Add(cOrderDate)
       
      ' Add the tables to the DataSet.
      myDataSet.Tables.Add(tCust)
      myDataSet.Tables.Add(tOrders)
        
      ' Create a DataRelation, and add it to the DataSet.
      Dim dr As New DataRelation("custToOrders", cCustID, cID)
      myDataSet.Relations.Add(dr)
        
      ' Populates the tables. For each customer and order, 
      ' creates two DataRow variables. 
      Dim newRow1 As DataRow
      Dim newRow2 As DataRow
        
      ' Create three customers in the Customers Table.
      Dim i As Integer
      For i = 1 To 3
         newRow1 = tCust.NewRow()
         newRow1("custID") = i
         ' Add the row to the Customers table.
         tCust.Rows.Add(newRow1)
      Next i
      ' Give each customer a distinct name.
      tCust.Rows(0)("custName") = "Customer1"
      tCust.Rows(1)("custName") = "Customer2"
      tCust.Rows(2)("custName") = "Customer3"
        
      ' Give the Current column a value.
      tCust.Rows(0)("Current") = True
      tCust.Rows(1)("Current") = True
      tCust.Rows(2)("Current") = False
        
      ' For each customer, create five rows in the Orders table.
      For i = 1 To 3
         Dim j As Integer
         For j = 1 To 5
            newRow2 = tOrders.NewRow()
            newRow2("CustID") = i
            newRow2("orderDate") = New DateTime(2001, i, j * 2)
            newRow2("OrderAmount") = i * 10 + j * 0.1
            ' Add the row to the Orders table.
            tOrders.Rows.Add(newRow2)
         Next j
      Next i
   End Sub 
End Class

備註

此類別在 .NET Core 3.1 和更新版本中無法使用。 請改用 DataGridView 控制項。

會顯示 System.Windows.Forms.DataGrid 類似 Web 的連結至子資料工作表。 您可以按一下連結以流覽至子資料工作表。 顯示子資料工作表時,返回按鈕會出現在可按一下的標題中,以巡覽回父資料表。 父資料列的資料會顯示在資料行標頭的標題和上方。 您可以按一下返回按鈕右邊的按鈕來隱藏父資料列資訊。

若要在執行時間顯示 資料表 System.Windows.Forms.DataGrid ,請使用 SetDataBinding 方法將 和 DataMember 屬性設定 DataSource 為有效的資料來源。 下列資料來源有效:

如需 類別的詳細資訊 DataSet ,請參閱 DataSets、DataTables 和 DataViews

您可以建立一個方格,讓使用者編輯資料,但防止他們新增資料列,方法是使用 DataView 做為資料來源,並將 屬性設定 AllowNewfalse

資料來源會由 BindingManagerBase 物件進一步管理。 針對資料來源中的每個資料表, BindingManagerBase 可以從表單 的 BindingContext 傳回 。 例如,您可以藉由傳回相關聯 BindingManagerBase 物件的 Count 屬性,來判斷資料來源所包含的資料列數目。

若要驗證資料,請使用代表資料及其事件的基礎物件。 例如,如果資料來自 DataTable 中的 DataSet ,請使用 ColumnChangingRowChanging 事件。

注意

由於可以藉由新增或刪除) 的成員 GridColumnStylesCollection 來自訂資料行數目 (,而且資料列可以依資料行排序, RowNumber 因此無法保證 和 ColumnNumber 屬性值對應至 DataRow 中的 和 DataColumn 索引 DataTable 。 因此,您應該避免在 事件中使用 Validating 那些屬性來驗證資料。

若要判斷選取哪一個儲存格,請使用 CurrentCell 屬性。 使用 Item[] 屬性來變更任何儲存格的值,其可採用儲存格的資料列和資料行索引,或單 DataGridCell 一 。 CurrentCellChanged監視事件,以偵測使用者何時選取另一個儲存格。

若要判斷使用者按一下的控制項哪個部分,請使用 HitTest 事件中的 MouseDown 方法。 方法 HitTest 會傳 DataGrid.HitTestInfo 回 物件,其中包含按一下區域的資料列和資料行。

若要管理控制項在執行時間的外觀,有數個屬性可用來設定色彩和標題屬性,包括 CaptionForeColorCaptionBackColorCaptionFont 等等。

您可以藉由建立 DataGridTableStyle 物件,並將其新增至 GridTableStylesCollection 可透過 TableStyles 屬性存取的 ,進一步修改顯示格線 (或) 格線的外觀。 例如,如果 DataSource 設定為包含三 DataTable 個物件的 ,您可以將三 DataGridTableStyleDataSet 物件新增至集合,每個資料表各有一個物件。 若要將每個 DataGridTableStyle 物件與 DataTable 同步處理,請將 的 DataGridTableStyle 設定 MappingNameTableNameDataTable 。 如需系結至物件陣列的詳細資訊,請參閱 DataGridTableStyle.MappingName 屬性。

若要建立資料表的自訂檢視,請建立 或 類別的 DataGridTextBoxColumn 實例,並將 物件加入至 GridTableStylesCollection 透過 屬性存取的 TableStylesDataGridBoolColumn 這兩個類別都是繼承自 DataGridColumnStyle。 針對每個資料行樣式,將 設定 MappingNameColumnName 為您要顯示在方格中之資料行的 。 若要隱藏資料行,請將它 MappingName 設定為有效的 ColumnName 以外的專案。

若要格式化資料行的文字,請將 FormatDataGridTextBoxColumn 屬性設定為 [格式化類型 ] 和 [自訂日期和時間格式字串] 中找到的其中一個值。

若要將 系結 DataGrid 至物件的強型別陣列,物件類型必須包含公用屬性。 若要建立 DataGridTableStyle 顯示陣列的 ,請將 DataGridTableStyle.MappingName 屬性設定為 typename[] ,其中 typename 會以物件類型的名稱取代。 另請注意, MappingName 屬性會區分大小寫;類型名稱必須完全符合。 如需範例, MappingName 請參閱 屬性。

您也可以將 系結 DataGridArrayList 。 的功能 ArrayList 是它可以包含多個類型的物件,但 DataGrid 只有在清單中的所有專案都與第一個專案相同時,才能系結至這類清單。 這表示所有物件都必須屬於相同的類型,或者它們必須繼承自與清單中第一個專案相同的類別。 例如,如果清單中的第一個專案是 Control ,第二個專案可能是 TextBox 繼承自 Control) (。 如果另一方面,第一個專案是 ,第二個 TextBoxControl 物件不能是 。 此外, ArrayList 在系結專案時,必須有其中的專案。 空 ArrayList 的將會產生空的方格。 此外,中的 ArrayList 物件必須包含公用屬性。 當系結至 ArrayList 時,請將 的 DataGridTableStyle 設定 MappingName 為 「ArrayList」 (類型名稱) 。

針對每個 DataGridTableStyle ,您可以設定色彩和標題屬性,以覆寫控制項的 System.Windows.Forms.DataGrid 設定。 不過,如果未設定這些屬性,預設會使用控制項的設定。 屬性可以覆寫 DataGridTableStyle 下列屬性:

若要自訂個別資料行的外觀,請將 物件新增 DataGridColumnStyleGridColumnStylesCollection ,其可透過 GridColumnStyles 每個 DataGridTableStyle 的 屬性存取。 若要將 中的每個 DataGridColumnStyleDataColumn 中的 DataTable 同步處理,請將 設定 MappingNameColumnNameDataColumn 。 建 DataGridColumnStyle 構 時,您也可以設定格式字串,指定資料行顯示資料的方式。 例如,您可以指定資料行使用簡短日期格式來顯示資料表中包含的日期。

警告

一律先建立 DataGridColumnStyle 物件,並在將物件新增至 GridColumnStylesCollection 之前將其新增 DataGridTableStyleGridTableStylesCollection 。 當您將具有有效 MappingName 值的空白 DataGridTableStyle 加入至集合時, DataGridColumnStyle 系統會自動為您產生 物件。 因此,如果您嘗試將具有重複 MappingName 值的新 DataGridColumnStyle 物件新增至 GridColumnStylesCollection ,就會擲回例外狀況。

注意

DataGridView 控制項會取代 DataGrid 控制項並加入其他功能,不過您也可以選擇保留 DataGrid 控制項,以提供回溯相容性及未來使用。 如需詳細資訊,請參閱 Windows Forms DataGridView 和 DataGrid 控制項之間的差異

建構函式

DataGrid()

初始化 DataGrid 類別的新執行個體。

屬性

AccessibilityObject

取得指定給控制項的 AccessibleObject

(繼承來源 Control)
AccessibleDefaultActionDescription

取得或設定協助用戶端應用程式所使用的控制項的預設動作描述。

(繼承來源 Control)
AccessibleDescription

取得或設定協助工具用戶端應用程式使用之控制項的描述。

(繼承來源 Control)
AccessibleName

取得或設定協助工具用戶端應用程式使用的控制項名稱。

(繼承來源 Control)
AccessibleRole

取得或設定控制項的可存取角色。

(繼承來源 Control)
AllowDrop

取得或設定值,指出控制項是否能接受使用者拖放上來的資料。

(繼承來源 Control)
AllowNavigation

取得或設定值,表示是否允許巡覽作業。

AllowSorting

取得或設定值,表示是否按一下資料行行首即可排序方格。

AlternatingBackColor

取得或設定方格奇數資料列的背景色彩。

Anchor

取得或設定控制項繫結至的容器邊緣,並決定控制項隨其父代重新調整大小的方式。

(繼承來源 Control)
AutoScrollOffset

取得或設定此控制項在 ScrollControlIntoView(Control) 中要捲動到哪一個位置。

(繼承來源 Control)
AutoSize

這個屬性與這個類別無關。

(繼承來源 Control)
BackColor

取得或設定方格其偶數資料列的背景色彩。

BackgroundColor

取得或設定方格的資料列以外區域的色彩。

BackgroundImage

這個成員對這個控制項來說不具意義。

BackgroundImageLayout

這個成員對這個控制項來說不具意義。

BackgroundImageLayout

取得或設定在 ImageLayout 列舉類型中所定義的背景影像配置。

(繼承來源 Control)
BindingContext

取得或設定控制項的 BindingContext

(繼承來源 Control)
BorderStyle

取得或設定方格的框線樣式。

Bottom

取得控制項下邊緣和其容器工作區 (Client Area) 上邊緣之間的距離 (單位為像素)。

(繼承來源 Control)
Bounds

取得或設定控制項 (包括其非工作區項目) 相對於父控制項之大小和位置 (單位為像素)。

(繼承來源 Control)
CanEnableIme

取得值,這個值表示 ImeMode 屬性是否可以設定為使用中的值,以啟用 IME 支援。

(繼承來源 Control)
CanFocus

取得指示控制項是否能取得焦點的值。

(繼承來源 Control)
CanRaiseEvents

判斷是否可以在控制項上引發事件。

(繼承來源 Control)
CanSelect

取得指示能否選取控制項的值。

(繼承來源 Control)
CaptionBackColor

取得或設定標題區域的背景色彩。

CaptionFont

取得或設定方格標題的字型。

CaptionForeColor

取得或設定標題區域的前景色彩。

CaptionText

取得或設定方格的視窗標題文字。

CaptionVisible

取得或設定值,表示方格標題是否可見。

Capture

取得或設定值,指出控制項是否捕捉住滑鼠。

(繼承來源 Control)
CausesValidation

取得或設定值,指出控制項取得焦點時,是否會在任何需要驗證的控制項上執行驗證。

(繼承來源 Control)
ClientRectangle

取得表示控制項工作區的矩形。

(繼承來源 Control)
ClientSize

取得或設定控制項工作區的高度和寬度。

(繼承來源 Control)
ColumnHeadersVisible

取得或設定值,表示資料表的資料行行首是否可見。

CompanyName

取得包含控制項之應用程式的公司名稱或建立者。

(繼承來源 Control)
Container

取得包含 IContainerComponent

(繼承來源 Component)
ContainsFocus

取得指示控制項 (或其子控制項之一) 目前是否擁有輸入焦點的值。

(繼承來源 Control)
ContextMenu

取得或設定與控制項關聯的捷徑功能表。

(繼承來源 Control)
ContextMenuStrip

取得或設定與這個控制項相關的 ContextMenuStrip

(繼承來源 Control)
Controls

取得控制項中包含的控制項集合。

(繼承來源 Control)
Created

取得值,指出是否已經建立控制項。

(繼承來源 Control)
CreateParams

建立控制代碼時,取得必要的建立參數。

(繼承來源 Control)
CurrentCell

取得或設定由那個儲存格取得焦點 (Focus)。 無法在設計階段使用。

CurrentRowIndex

取得或設定目前具有焦點之資料列的索引。

Cursor

這個成員對這個控制項來說不具意義。

DataBindings

取得控制項的資料繫結 (Data Binding)。

(繼承來源 Control)
DataContext

取得或設定資料系結用途的資料內容。 這是環境屬性。

(繼承來源 Control)
DataMember

取得或設定 DataSource 中的特定清單,DataGrid 控制項將使用方格顯示這個清單。

DataSource

取得或設定在方格中顯示資料的資料來源。

DefaultCursor

取得或設定控制項的預設游標。

(繼承來源 Control)
DefaultImeMode

取得控制項支援的預設輸入法 (IME) 模式。

(繼承來源 Control)
DefaultMargin

取得控制項之間的預設指定間距 (單位為像素)。

(繼承來源 Control)
DefaultMaximumSize

取得指定為控制項的預設大小之最大值的長度和高度 (單位為像素)。

(繼承來源 Control)
DefaultMinimumSize

取得指定為控制項的預設大小之最小值的長度和高度 (單位為像素)。

(繼承來源 Control)
DefaultPadding

取得控制項內容的內部間距 (單位為像素)。

(繼承來源 Control)
DefaultSize

取得控制項的預設大小。

DesignMode

取得值,指出 Component 目前是否處於設計模式。

(繼承來源 Component)
DeviceDpi

取得目前顯示控制項的顯示裝置的 DPI 值。

(繼承來源 Control)
DisplayRectangle

取得表示控制項顯示區域的矩形。

(繼承來源 Control)
Disposing

取得值,指出基底 Control 類別是否正在處置的過程中。

(繼承來源 Control)
Dock

取得或設定停駐在其父控制項的控制項框線,並決定控制項隨其父代重新調整大小的方式。

(繼承來源 Control)
DoubleBuffered

取得或設定值,指出這個控制項是否應使用次要緩衝區重繪其介面,以減少或防止重繪閃動 (Flicker)。

(繼承來源 Control)
Enabled

取得或設定值,指出控制項是否可回應使用者互動。

(繼承來源 Control)
Events

取得附加在這個 Component 上的事件處理常式清單。

(繼承來源 Component)
FirstVisibleColumn

取得方格第一個可見資料行的索引。

FlatMode

取得或設定值,表示是否以一般模式顯示方格。

Focused

取得指示控制項是否擁有輸入焦點的值。

(繼承來源 Control)
Font

取得或設定控制項顯示之文字字型。

(繼承來源 Control)
FontHeight

取得或設定控制項字型的高度。

(繼承來源 Control)
ForeColor

取得或設定 DataGrid 控制項的前景色彩 (通常是文字的色彩) 屬性。

GridLineColor

取得或設定格線色彩。

GridLineStyle

取得或設定格線樣式。

Handle

取得控制項要繫結的目標視窗控制代碼。

(繼承來源 Control)
HasChildren

取得指示控制項是否包含一或多個子控制項的值。

(繼承來源 Control)
HeaderBackColor

取得或設定所有資料列和資料行行首的背景色彩。

HeaderFont

取得或設定資料行行首使用的字型。

HeaderForeColor

取得或設定標頭的前景色彩。

Height

取得或設定控制項的高度。

(繼承來源 Control)
HorizScrollBar

取得方格的水平捲軸。

ImeMode

取得或設定控制項的輸入法 (IME) 模式。

(繼承來源 Control)
ImeModeBase

取得或設定控制項的 IME 模式。

(繼承來源 Control)
InvokeRequired

取得一個值。這個值會指示是否由於呼叫端是在建立控制項之執行緒以外的執行緒,因此在進行控制項的方法呼叫時,應呼叫叫用 (Invoke) 方法。

(繼承來源 Control)
IsAccessible

取得或設定值,指出可及性應用程式是否見得到控制項。

(繼承來源 Control)
IsAncestorSiteInDesignMode

指出此控制項的其中一個上階是否已月臺,且該月臺位於 DesignMode 中。 這個屬性是唯讀的。

(繼承來源 Control)
IsDisposed

取得指示控制項是否已經處置的值。

(繼承來源 Control)
IsHandleCreated

取得指示控制項是否有相關控制代碼的值。

(繼承來源 Control)
IsMirrored

取得值,指出是否左右反轉控制項。

(繼承來源 Control)
Item[DataGridCell]

取得或設定指定的 DataGridCell 值。

Item[Int32, Int32]

取得或設定指定資料列和資料行儲存格的值。

LayoutEngine

取得控制項之配置引擎的快取執行個體。

(繼承來源 Control)
Left

取得或設定控制項左邊緣和其容器工作區 (Client Area) 左邊緣之間的距離 (單位為像素)。

(繼承來源 Control)
LinkColor

取得或設定文字色彩,按一下這個文字便可巡覽至子資料表。

LinkHoverColor

這個成員對這個控制項來說不具意義。

ListManager

取得這個 CurrencyManager 控制項的 DataGrid

Location

取得或設定對應至控制項容器左上角之控制項左上角的座標。

(繼承來源 Control)
Margin

取得或設定控制項之間的空格。

(繼承來源 Control)
MaximumSize

取得或設定 GetPreferredSize(Size) 可以指定的上限大小。

(繼承來源 Control)
MinimumSize

取得或設定 GetPreferredSize(Size) 可以指定的下限大小。

(繼承來源 Control)
Name

取得或設定控制項的名稱。

(繼承來源 Control)
Padding

取得或設定控制項內的邊框間距。

(繼承來源 Control)
Parent

取得或設定控制項的父容器。

(繼承來源 Control)
ParentRowsBackColor

取得或設定父資料列的背景色彩。

ParentRowsForeColor

取得或設定父資料列的前景色彩。

ParentRowsLabelStyle

取得或設定父資料列標籤的顯示方式。

ParentRowsVisible

取得或設定值,表示資料表的父資料列是否可見。

PreferredColumnWidth

取得或設定方格中資料行的預設寬度,單位為像素。

PreferredRowHeight

取得或設定 DataGrid 控制項的慣用資料列高度。

PreferredSize

取得能夠容納控制項的矩形區域的大小。

(繼承來源 Control)
ProductName

取得包含控制項的組件的產品名稱。

(繼承來源 Control)
ProductVersion

取得包含控制項的組件的版本。

(繼承來源 Control)
ReadOnly

取得或設定值,表示方格是否在唯讀模式中。

RecreatingHandle

取得指示控制項目前是否正重新建立其控制代碼的值。

(繼承來源 Control)
Region

取得或設定與控制項關聯的視窗區域。

(繼承來源 Control)
RenderRightToLeft
已淘汰.
已淘汰.

此屬性現在已過時。

(繼承來源 Control)
ResizeRedraw

取得或設定值,指出控制項重設大小時,是否會重繪本身。

(繼承來源 Control)
Right

取得控制項右邊緣和其容器工作區 (Client Area) 左邊緣之間的距離 (單位為像素)。

(繼承來源 Control)
RightToLeft

取得或設定值,指出控制項的項目是否對齊,以支援使用由右至左字型的地區設定。

(繼承來源 Control)
RowHeadersVisible

取得或設定值,指定資料列標頭是否可見。

RowHeaderWidth

取得或設定資料列標頭的寬度。

ScaleChildren

取得值,以判斷子控制項的縮放。

(繼承來源 Control)
SelectionBackColor

取得或設定選取資料列的背景色彩。

SelectionForeColor

取得或設定選取資料列的前景色彩。

ShowFocusCues

取得指示控制項是否應顯示焦點矩形 (Focus Rectangle) 的值。

(繼承來源 Control)
ShowKeyboardCues

取得值,指出使用者介面是否處於可顯示或隱藏鍵盤快速鍵的適當狀態下。

(繼承來源 Control)
Site

取得或設定控制項的站台。

Size

取得或設定控制項的高度和寬度。

(繼承來源 Control)
TabIndex

取得或設定控制項容器中的控制項定位順序。

(繼承來源 Control)
TableStyles

取得方格中 DataGridTableStyle 物件的集合。

TabStop

取得或設定值,指出使用者是否能使用 TAB 鍵,將焦點 (Focus) 給予這個控制項。

(繼承來源 Control)
Tag

取得或設定物件,其包含控制項相關資料。

(繼承來源 Control)
Text

這個成員對這個控制項來說不具意義。

Top

取得或設定控制項上邊緣和其容器工作區 (Client Area) 上邊緣之間的距離 (單位為像素)。

(繼承來源 Control)
TopLevelControl

取得沒有其他 Windows Form 父控制項的父控制項。 通常,這會是內含控制項最外層的 Form

(繼承來源 Control)
UseWaitCursor

取得或設定值,指出是否將等待游標用於目前控制項和所有子控制項。

(繼承來源 Control)
VertScrollBar

取得控制項的垂直捲軸。

Visible

取得或設定值,這個值指出是否顯示控制項及其所有子控制項。

(繼承來源 Control)
VisibleColumnCount

取得可見的資料行編號。

VisibleRowCount

取得可見資料列的編號。

Width

取得或設定控制項的寬度。

(繼承來源 Control)
WindowTarget

這個屬性與這個類別無關。

(繼承來源 Control)

方法

AccessibilityNotifyClients(AccessibleEvents, Int32)

將指定子控制項的指定 AccessibleEvents 告知協助工具用戶端應用程式。

(繼承來源 Control)
AccessibilityNotifyClients(AccessibleEvents, Int32, Int32)

將指定子控制項的指定 AccessibleEvents 告知協助工具用戶端應用程式。

(繼承來源 Control)
BeginEdit(DataGridColumnStyle, Int32)

嘗試將方格放入允許編輯的狀態中。

BeginInit()

開始對表單或另一個元件所使用的 DataGrid 進行初始化作業。 初始化發生於執行階段。

BeginInvoke(Action)

在建立控制項基礎控制代碼的執行緒上執行指定的非同步委派。

(繼承來源 Control)
BeginInvoke(Delegate)

在建立控制項基礎控制代碼的執行緒上執行指定的非同步委派。

(繼承來源 Control)
BeginInvoke(Delegate, Object[])

在建立控制項基礎控制代碼的執行緒上,以指定的引數非同步執行指定的委派。

(繼承來源 Control)
BringToFront()

將控制項帶到疊置順序的前面。

(繼承來源 Control)
CancelEditing()

取消目前編輯作業並復原所有變更。

Collapse(Int32)

如果所有資料列或指定的資料列存在任何的子關聯,請摺疊該子關聯。

ColumnStartedEditing(Control)

通知 DataGrid 控制項使用者何時開始使用指定的控制項編輯資料行。

ColumnStartedEditing(Rectangle)

通知 DataGrid 控制項使用者何時在指定的位置開始編輯資料行。

Contains(Control)

擷取指示控制項是否為控制項的子控制項的值。

(繼承來源 Control)
CreateAccessibilityInstance()

建構這個控制項之存取範圍物件的新執行個體。

CreateControl()

強制建立可見控制項,包含建立控制代碼和任何可見的子控制項。

(繼承來源 Control)
CreateControlsInstance()

建立控制項的控制項集合的新執行個體。

(繼承來源 Control)
CreateGraphics()

建立控制項的 Graphics

(繼承來源 Control)
CreateGridColumn(PropertyDescriptor)

使用指定的 DataGridColumnStyle 建立新 PropertyDescriptor

CreateGridColumn(PropertyDescriptor, Boolean)

使用指定的 DataGridColumnStyle 來建立 PropertyDescriptor

CreateHandle()

建立控制項的控制代碼。

(繼承來源 Control)
CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
DefWndProc(Message)

傳送指定的訊息至預設的視窗程序。

(繼承來源 Control)
DestroyHandle()

終結與這個控制項相關的控制代碼。

(繼承來源 Control)
Dispose()

釋放 Component 所使用的所有資源。

(繼承來源 Component)
Dispose(Boolean)

處置 (Dispose) DataGrid 所使用的資源 (除了記憶體之外)。

DoDragDrop(Object, DragDropEffects)

開始拖放作業。

(繼承來源 Control)
DoDragDrop(Object, DragDropEffects, Bitmap, Point, Boolean)

開始拖曳作業。

(繼承來源 Control)
DrawToBitmap(Bitmap, Rectangle)

支援呈現為指定的點陣圖。

(繼承來源 Control)
EndEdit(DataGridColumnStyle, Int32, Boolean)

要求結束 DataGrid 控制項的編輯作業。

EndInit()

結束對表單或另一個元件所使用的 DataGrid 進行初始化作業。 初始化發生於執行階段。

EndInvoke(IAsyncResult)

擷取由傳遞的 IAsyncResult 表示的非同步作業的傳回值。

(繼承來源 Control)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
Expand(Int32)

顯示所有資料列或指定資料列的子關聯 (如果存在的話)。

FindForm()

擷取控制項所在的表單。

(繼承來源 Control)
Focus()

設定控制項的輸入焦點。

(繼承來源 Control)
GetAccessibilityObjectById(Int32)

擷取指定的 AccessibleObject

(繼承來源 Control)
GetAutoSizeMode()

擷取值,表示已啟用控制項的 AutoSize 屬性時,該控制項的行為模式為何。

(繼承來源 Control)
GetCellBounds(DataGridCell)

取得 Rectangle 指定之儲存格的 DataGridCell

GetCellBounds(Int32, Int32)

取得資料列和資料行編號所指定的儲存格 Rectangle

GetChildAtPoint(Point)

擷取位於指定座標的子控制項。

(繼承來源 Control)
GetChildAtPoint(Point, GetChildAtPointSkip)

擷取位於指定座標上的子控制項,指定是否要忽略特定類型的子控制項。

(繼承來源 Control)
GetContainerControl()

傳回父控制項的控制項鏈結上的下一個 ContainerControl

(繼承來源 Control)
GetCurrentCellBounds()

取得指定選取儲存格四個角落的 Rectangle

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetNextControl(Control, Boolean)

擷取子控制項定位順序中前後的下一個控制項。

(繼承來源 Control)
GetOutputTextDelimiter()

取得字串,這個字串是將資料列內容複製至剪貼簿時,介於資料行之間的分隔符號 (Delimiter)。

GetPreferredSize(Size)

擷取可容納控制項之矩形區域的大小。

(繼承來源 Control)
GetScaledBounds(Rectangle, SizeF, BoundsSpecified)

擷取縮放控制項的範圍。

(繼承來源 Control)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。

(繼承來源 Component)
GetStyle(ControlStyles)

擷取控制項指定控制項樣式位元的值。

(繼承來源 Control)
GetTopLevel()

判斷控制項是否為最上層控制項。

(繼承來源 Control)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GridHScrolled(Object, ScrollEventArgs)

接聽水平捲軸的捲動事件。

GridVScrolled(Object, ScrollEventArgs)

接聽垂直捲軸的捲動事件。

Hide()

對使用者隱藏控制項。

(繼承來源 Control)
HitTest(Int32, Int32)

使用傳遞至這個方法的 x 和 y 座標來取得資訊,例如方格上按下點的資料列和資料行編號。

HitTest(Point)

取得使用指定 Point 方格的相關資料,例如方格上按下點的資料列和資料行編號。

InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
InitLayout()

在控制項加入其他容器後呼叫。

(繼承來源 Control)
Invalidate()

讓控制項的整個介面失效,並重新繪製控制項。

(繼承來源 Control)
Invalidate(Boolean)

使控制項的特定區域失效,並且造成傳送繪製訊息至控制項。 選擇性使指派至控制項的子控制項失效。

(繼承來源 Control)
Invalidate(Rectangle)

使控制項的指定區域失效 (將它加入控制項的更新區域,而這個區域會在下一個繪製作業中重新繪製),並使繪製訊息傳送至控制項。

(繼承來源 Control)
Invalidate(Rectangle, Boolean)

使控制項的指定區域失效 (將它加入控制項的更新區域,而這個區域會在下一個繪製作業中重新繪製),並使繪製訊息傳送至控制項。 選擇性使指派至控制項的子控制項失效。

(繼承來源 Control)
Invalidate(Region)

使控制項的指定區域失效 (將它加入控制項的更新區域,而這個區域會在下一個繪製作業中重新繪製),並使繪製訊息傳送至控制項。

(繼承來源 Control)
Invalidate(Region, Boolean)

使控制項的指定區域失效 (將它加入控制項的更新區域,而這個區域會在下一個繪製作業中重新繪製),並使繪製訊息傳送至控制項。 選擇性使指派至控制項的子控制項失效。

(繼承來源 Control)
Invoke(Action)

在擁有控制項基礎視窗控制代碼的執行緒上執行指定的委派。

(繼承來源 Control)
Invoke(Delegate)

在擁有控制項基礎視窗控制代碼的執行緒上執行指定的委派。

(繼承來源 Control)
Invoke(Delegate, Object[])

在擁有控制項基礎視窗控制代碼的執行緒上,以指定的引數清單執行指定的委派。

(繼承來源 Control)
Invoke<T>(Func<T>)

在擁有控制項基礎視窗控制代碼的執行緒上執行指定的委派。

(繼承來源 Control)
InvokeGotFocus(Control, EventArgs)

引發指定之控制項的 GotFocus 事件。

(繼承來源 Control)
InvokeLostFocus(Control, EventArgs)

引發指定之控制項的 LostFocus 事件。

(繼承來源 Control)
InvokeOnClick(Control, EventArgs)

引發指定之控制項的 Click 事件。

(繼承來源 Control)
InvokePaint(Control, PaintEventArgs)

引發指定之控制項的 Paint 事件。

(繼承來源 Control)
InvokePaintBackground(Control, PaintEventArgs)

引發指定之控制項的 PaintBackground 事件。

(繼承來源 Control)
IsExpanded(Int32)

取得值,表示指定資料列的節點是展開還是摺疊。

IsInputChar(Char)

判斷字元是否為控制項辨認的輸入字元。

(繼承來源 Control)
IsInputKey(Keys)

判斷指定的按鍵是標準輸入按鍵或需要前置處理的特殊按鍵。

(繼承來源 Control)
IsSelected(Int32)

取得值,表示是否選取指定的資料列。

LogicalToDeviceUnits(Int32)

將邏輯 DPI 值轉換為它的對等 DeviceUnit DPI 值。

(繼承來源 Control)
LogicalToDeviceUnits(Size)

針對目前的 DPI 調整大小,並四捨五入為最接近的寬度和高度整數值,以將大小從邏輯轉換成裝置單位。

(繼承來源 Control)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
NavigateBack()

向後巡覽至先前方格顯示的資料表。

NavigateTo(Int32, String)

巡覽至資料列和關聯名稱指定的資料表。

NotifyInvalidate(Rectangle)

引發 Invalidated 事件,包含要失效的指定控制項區域。

(繼承來源 Control)
OnAllowNavigationChanged(EventArgs)

引發 AllowNavigationChanged 事件。

OnAutoSizeChanged(EventArgs)

引發 AutoSizeChanged 事件。

(繼承來源 Control)
OnBackButtonClicked(Object, EventArgs)

接聽標題的上一步按鈕按下事件。

OnBackColorChanged(EventArgs)

引發 BackColorChanged 事件。

OnBackgroundColorChanged(EventArgs)

引發 BackgroundColorChanged 事件。

OnBackgroundImageChanged(EventArgs)

引發 BackgroundImageChanged 事件。

(繼承來源 Control)
OnBackgroundImageLayoutChanged(EventArgs)

引發 BackgroundImageLayoutChanged 事件。

(繼承來源 Control)
OnBindingContextChanged(EventArgs)

引發 BindingContextChanged 事件。

OnBorderStyleChanged(EventArgs)

引發 BorderStyleChanged 事件。

OnCaptionVisibleChanged(EventArgs)

引發 CaptionVisibleChanged 事件。

OnCausesValidationChanged(EventArgs)

引發 CausesValidationChanged 事件。

(繼承來源 Control)
OnChangeUICues(UICuesEventArgs)

引發 ChangeUICues 事件。

(繼承來源 Control)
OnClick(EventArgs)

引發 Click 事件。

(繼承來源 Control)
OnClientSizeChanged(EventArgs)

引發 ClientSizeChanged 事件。

(繼承來源 Control)
OnContextMenuChanged(EventArgs)

引發 ContextMenuChanged 事件。

(繼承來源 Control)
OnContextMenuStripChanged(EventArgs)

引發 ContextMenuStripChanged 事件。

(繼承來源 Control)
OnControlAdded(ControlEventArgs)

引發 ControlAdded 事件。

(繼承來源 Control)
OnControlRemoved(ControlEventArgs)

引發 ControlRemoved 事件。

(繼承來源 Control)
OnCreateControl()

引發 CreateControl() 方法。

(繼承來源 Control)
OnCurrentCellChanged(EventArgs)

引發 CurrentCellChanged 事件。

OnCursorChanged(EventArgs)

引發 CursorChanged 事件。

(繼承來源 Control)
OnDataContextChanged(EventArgs)

在可捲動方格中顯示 ADO.NET 資料。

此類別在 .NET Core 3.1 和更新版本中無法使用。 請改用 DataGridView 控制項,以取代和擴充 DataGrid 控制項。

(繼承來源 Control)
OnDataSourceChanged(EventArgs)

引發 DataSourceChanged 事件。

OnDockChanged(EventArgs)

引發 DockChanged 事件。

(繼承來源 Control)
OnDoubleClick(EventArgs)

引發 DoubleClick 事件。

(繼承來源 Control)
OnDpiChangedAfterParent(EventArgs)

引發 DpiChangedAfterParent 事件。

(繼承來源 Control)
OnDpiChangedBeforeParent(EventArgs)

引發 DpiChangedBeforeParent 事件。

(繼承來源 Control)
OnDragDrop(DragEventArgs)

引發 DragDrop 事件。

(繼承來源 Control)
OnDragEnter(DragEventArgs)

引發 DragEnter 事件。

(繼承來源 Control)
OnDragLeave(EventArgs)

引發 DragLeave 事件。

(繼承來源 Control)
OnDragOver(DragEventArgs)

引發 DragOver 事件。

(繼承來源 Control)
OnEnabledChanged(EventArgs)

引發 EnabledChanged 事件。

(繼承來源 Control)
OnEnter(EventArgs)

引發 Enter 事件。

OnFlatModeChanged(EventArgs)

引發 FlatModeChanged 事件。

OnFontChanged(EventArgs)

引發 FontChanged 事件。

OnForeColorChanged(EventArgs)

引發 ForeColorChanged 事件。

OnGiveFeedback(GiveFeedbackEventArgs)

引發 GiveFeedback 事件。

(繼承來源 Control)
OnGotFocus(EventArgs)

引發 GotFocus 事件。

(繼承來源 Control)
OnHandleCreated(EventArgs)

引發 CreateHandle() 事件。

OnHandleDestroyed(EventArgs)

引發 DestroyHandle() 事件。

OnHelpRequested(HelpEventArgs)

引發 HelpRequested 事件。

(繼承來源 Control)
OnImeModeChanged(EventArgs)

引發 ImeModeChanged 事件。

(繼承來源 Control)
OnInvalidated(InvalidateEventArgs)

引發 Invalidated 事件。

(繼承來源 Control)
OnKeyDown(KeyEventArgs)

引發 KeyDown 事件。

OnKeyPress(KeyPressEventArgs)

引發 KeyPress 事件。

OnKeyUp(KeyEventArgs)

引發 KeyUp 事件。

(繼承來源 Control)
OnLayout(LayoutEventArgs)

引發重新調整控制項位置並更新捲軸的 Layout 事件。

OnLeave(EventArgs)

引發 Leave 事件。

OnLocationChanged(EventArgs)

引發 LocationChanged 事件。

(繼承來源 Control)
OnLostFocus(EventArgs)

引發 LostFocus 事件。

(繼承來源 Control)
OnMarginChanged(EventArgs)

引發 MarginChanged 事件。

(繼承來源 Control)
OnMouseCaptureChanged(EventArgs)

引發 MouseCaptureChanged 事件。

(繼承來源 Control)
OnMouseClick(MouseEventArgs)

引發 MouseClick 事件。

(繼承來源 Control)
OnMouseDoubleClick(MouseEventArgs)

引發 MouseDoubleClick 事件。

(繼承來源 Control)
OnMouseDown(MouseEventArgs)

引發 MouseDown 事件。

OnMouseEnter(EventArgs)

引發 MouseEnter 事件。

(繼承來源 Control)
OnMouseHover(EventArgs)

引發 MouseHover 事件。

(繼承來源 Control)
OnMouseLeave(EventArgs)

建立 MouseLeave 事件。

OnMouseMove(MouseEventArgs)

引發 MouseMove 事件。

OnMouseUp(MouseEventArgs)

引發 MouseUp 事件。

OnMouseWheel(MouseEventArgs)

引發 MouseWheel 事件。

OnMove(EventArgs)

引發 Move 事件。

(繼承來源 Control)
OnNavigate(NavigateEventArgs)

引發 Navigate 事件。

OnNotifyMessage(Message)

將 Windows 訊息通知控制項。

(繼承來源 Control)
OnPaddingChanged(EventArgs)

引發 PaddingChanged 事件。

(繼承來源 Control)
OnPaint(PaintEventArgs)

引發 Paint 事件。

OnPaintBackground(PaintEventArgs)

覆寫 OnPaintBackground(PaintEventArgs) 以防止 DataGrid 控制項背景繪製。

OnParentBackColorChanged(EventArgs)

當控制項容器的 BackColorChanged 屬性值變更時,會引發 BackColor 事件。

(繼承來源 Control)
OnParentBackgroundImageChanged(EventArgs)

當控制項容器的 BackgroundImageChanged 屬性值變更時,會引發 BackgroundImage 事件。

(繼承來源 Control)
OnParentBindingContextChanged(EventArgs)

當控制項容器的 BindingContextChanged 屬性值變更時,會引發 BindingContext 事件。

(繼承來源 Control)
OnParentChanged(EventArgs)

引發 ParentChanged 事件。

(繼承來源 Control)
OnParentCursorChanged(EventArgs)

引發 CursorChanged 事件。

(繼承來源 Control)
OnParentDataContextChanged(EventArgs)

在可捲動方格中顯示 ADO.NET 資料。

此類別在 .NET Core 3.1 和更新版本中無法使用。 請改用 DataGridView 控制項,以取代和擴充 DataGrid 控制項。

(繼承來源 Control)
OnParentEnabledChanged(EventArgs)

當控制項容器的 EnabledChanged 屬性值變更時,會引發 Enabled 事件。

(繼承來源 Control)
OnParentFontChanged(EventArgs)

當控制項容器的 FontChanged 屬性值變更時,會引發 Font 事件。

(繼承來源 Control)
OnParentForeColorChanged(EventArgs)

當控制項容器的 ForeColorChanged 屬性值變更時,會引發 ForeColor 事件。

(繼承來源 Control)
OnParentRightToLeftChanged(EventArgs)

當控制項容器的 RightToLeftChanged 屬性值變更時,會引發 RightToLeft 事件。

(繼承來源 Control)
OnParentRowsLabelStyleChanged(EventArgs)

引發 ParentRowsLabelStyleChanged 事件。

OnParentRowsVisibleChanged(EventArgs)

引發 ParentRowsVisibleChanged 事件。

OnParentVisibleChanged(EventArgs)

當控制項容器的 VisibleChanged 屬性值變更時,會引發 Visible 事件。

(繼承來源 Control)
OnPreviewKeyDown(PreviewKeyDownEventArgs)

引發 PreviewKeyDown 事件。

(繼承來源 Control)
OnPrint(PaintEventArgs)

引發 Paint 事件。

(繼承來源 Control)
OnQueryContinueDrag(QueryContinueDragEventArgs)

引發 QueryContinueDrag 事件。

(繼承來源 Control)
OnReadOnlyChanged(EventArgs)

引發 ReadOnlyChanged 事件。

OnRegionChanged(EventArgs)

引發 RegionChanged 事件。

(繼承來源 Control)
OnResize(EventArgs)

引發 Resize 事件。

OnRightToLeftChanged(EventArgs)

引發 RightToLeftChanged 事件。

(繼承來源 Control)
OnRowHeaderClick(EventArgs)

引發 RowHeaderClick 事件。

OnScroll(EventArgs)

引發 Scroll 事件。

OnShowParentDetailsButtonClicked(Object, EventArgs)

引發 ShowParentDetailsButtonClick 事件。

OnSizeChanged(EventArgs)

引發 SizeChanged 事件。

(繼承來源 Control)
OnStyleChanged(EventArgs)

引發 StyleChanged 事件。

(繼承來源 Control)
OnSystemColorsChanged(EventArgs)

引發 SystemColorsChanged 事件。

(繼承來源 Control)
OnTabIndexChanged(EventArgs)

引發 TabIndexChanged 事件。

(繼承來源 Control)
OnTabStopChanged(EventArgs)

引發 TabStopChanged 事件。

(繼承來源 Control)
OnTextChanged(EventArgs)

引發 TextChanged 事件。

(繼承來源 Control)
OnValidated(EventArgs)

引發 Validated 事件。

(繼承來源 Control)
OnValidating(CancelEventArgs)

引發 Validating 事件。

(繼承來源 Control)
OnVisibleChanged(EventArgs)

引發 VisibleChanged 事件。

(繼承來源 Control)
PerformLayout()

強制控制項將配置邏輯套用至其所有子控制項。

(繼承來源 Control)
PerformLayout(Control, String)

強制控制項將配置邏輯套用至其所有子控制項。

(繼承來源 Control)
PointToClient(Point)

將指定的螢幕點的位置計算為工作區座標 (Client Coordinate)。

(繼承來源 Control)
PointToScreen(Point)

將指定的工作區點的位置計算為螢幕座標。

(繼承來源 Control)
PreProcessControlMessage(Message)

先於訊息迴圈中前置處理鍵盤或輸入訊息後,再分派這些訊息。

(繼承來源 Control)
PreProcessMessage(Message)

先於訊息迴圈中前置處理鍵盤或輸入訊息後,再分派這些訊息。

(繼承來源 Control)
ProcessCmdKey(Message, Keys)

處理命令按鍵。

(繼承來源 Control)
ProcessDialogChar(Char)

處理對話方塊字元。

(繼承來源 Control)
ProcessDialogKey(Keys)

取得或設定值,表示是否進一步處理按鍵。

ProcessGridKey(KeyEventArgs)

處理格線巡視按鍵。

ProcessKeyEventArgs(Message)

處理按鍵訊息,並產生適當的控制項事件。

(繼承來源 Control)
ProcessKeyMessage(Message)

處理鍵盤訊息。

(繼承來源 Control)
ProcessKeyPreview(Message)

預覽鍵盤訊息並傳回數值,表示按鍵的使用狀況。

ProcessMnemonic(Char)

處理助憶鍵字元。

(繼承來源 Control)
ProcessTabKey(Keys)

取得值,表示是否應該處理 Tab 鍵。

RaiseDragEvent(Object, DragEventArgs)

引發適當的拖曳事件。

(繼承來源 Control)
RaiseKeyEvent(Object, KeyEventArgs)

引發適當的按鍵事件。

(繼承來源 Control)
RaiseMouseEvent(Object, MouseEventArgs)

引發適當的滑鼠事件。

(繼承來源 Control)
RaisePaintEvent(Object, PaintEventArgs)

引發適當的繪製事件。

(繼承來源 Control)
RecreateHandle()

強制重新建立控制項的控制代碼。

(繼承來源 Control)
RectangleToClient(Rectangle)

以工作區座標計算指定的螢幕矩形大小和位置。

(繼承來源 Control)
RectangleToScreen(Rectangle)

以螢幕座標計算指定的工作區矩形大小和位置。

(繼承來源 Control)
Refresh()

強制控制項使其工作區失效,並且立即重繪其本身和任何子控制項。

(繼承來源 Control)
RescaleConstantsForDpi(Int32, Int32)

提供在發生 DPI 變更時用來重新調整控制項的常數。

(繼承來源 Control)
ResetAlternatingBackColor()

重設 AlternatingBackColor 屬性為其預設色彩。

ResetBackColor()

重設 BackColor 屬性為其預設值。

ResetBindings()

使得繫結至 BindingSource 的控制項重新讀取清單中的所有項目,並重新整理其顯示的值。

(繼承來源 Control)
ResetCursor()

重設 Cursor 屬性為其預設值。

(繼承來源 Control)
ResetFont()

重設 Font 屬性為其預設值。

(繼承來源 Control)
ResetForeColor()

重設 ForeColor 屬性為其預設值。

ResetGridLineColor()

重設 GridLineColor 屬性為其預設值。

ResetHeaderBackColor()

重設 HeaderBackColor 屬性為其預設值。

ResetHeaderFont()

重設 HeaderFont 屬性為其預設值。

ResetHeaderForeColor()

重設 HeaderForeColor 屬性為其預設值。

ResetImeMode()

重設 ImeMode 屬性為其預設值。

(繼承來源 Control)
ResetLinkColor()

重設 LinkColor 屬性為其預設值。

ResetLinkHoverColor()

重設 LinkHoverColor 屬性為其預設值。

ResetMouseEventArgs()

重設控制項來處理 MouseLeave 事件。

(繼承來源 Control)
ResetRightToLeft()

重設 RightToLeft 屬性為其預設值。

(繼承來源 Control)
ResetSelection()

關閉所有選取資料列的選取範圍。

ResetSelectionBackColor()

重設 SelectionBackColor 屬性為其預設值。

ResetSelectionForeColor()

重設 SelectionForeColor 屬性為其預設值。

ResetText()

Text 屬性重設為其預設值 (Empty)。

(繼承來源 Control)
ResumeLayout()

繼續平常的配置邏輯。

(繼承來源 Control)
ResumeLayout(Boolean)

繼續平常的配置邏輯,選擇性地強制暫止配置要求的立即配置。

(繼承來源 Control)
RtlTranslateAlignment(ContentAlignment)

將指定的 ContentAlignment 轉換為適當的 ContentAlignment,以支援由右至左的文字。

(繼承來源 Control)
RtlTranslateAlignment(HorizontalAlignment)

將指定的 HorizontalAlignment 轉換為適當的 HorizontalAlignment,以支援由右至左的文字。

(繼承來源 Control)
RtlTranslateAlignment(LeftRightAlignment)

將指定的 LeftRightAlignment 轉換為適當的 LeftRightAlignment,以支援由右至左的文字。

(繼承來源 Control)
RtlTranslateContent(ContentAlignment)

將指定的 ContentAlignment 轉換為適當的 ContentAlignment,以支援由右至左的文字。

(繼承來源 Control)
RtlTranslateHorizontal(HorizontalAlignment)

將指定的 HorizontalAlignment 轉換為適當的 HorizontalAlignment,以支援由右至左的文字。

(繼承來源 Control)
RtlTranslateLeftRight(LeftRightAlignment)

將指定的 LeftRightAlignment 轉換為適當的 LeftRightAlignment,以支援由右至左的文字。

(繼承來源 Control)
Scale(Single)
已淘汰.
已淘汰.

縮放控制項和任何的子控制項。

(繼承來源 Control)
Scale(Single, Single)
已淘汰.
已淘汰.

縮放整個控制項和任何的子控制項。

(繼承來源 Control)
Scale(SizeF)

根據指定的縮放比例來縮放控制項和所有子控制項。

(繼承來源 Control)
ScaleBitmapLogicalToDevice(Bitmap)

發生 DPI 變更時,將邏輯點陣圖值調整為它的對等裝置單位值。

(繼承來源 Control)
ScaleControl(SizeF, BoundsSpecified)

縮放控制項的位置、大小、邊框間距和邊界。

(繼承來源 Control)
ScaleCore(Single, Single)

這個方法與這個類別無關。

(繼承來源 Control)
Select()

啟動控制項。

(繼承來源 Control)
Select(Boolean, Boolean)

啟動子控制項。 選擇性指定定位順序中要選取控制項的方向。

(繼承來源 Control)
Select(Int32)

選取指定的資料列。

SelectNextControl(Control, Boolean, Boolean, Boolean, Boolean)

啟動下一個控制項。

(繼承來源 Control)
SendToBack()

將控制項傳送到疊置順序的後面。

(繼承來源 Control)
SetAutoSizeMode(AutoSizeMode)

設定值,表示已啟用控制項的 AutoSize 屬性時,該控制項的行為模式為何。

(繼承來源 Control)
SetBounds(Int32, Int32, Int32, Int32)

將控制項的範圍設定為指定的位置和大小。

(繼承來源 Control)
SetBounds(Int32, Int32, Int32, Int32, BoundsSpecified)

將控制項的指定範圍設定為指定的位置和大小。

(繼承來源 Control)
SetBoundsCore(Int32, Int32, Int32, Int32, BoundsSpecified)

執行設定這個控制項的指定範圍的工作。

(繼承來源 Control)
SetClientSizeCore(Int32, Int32)

設定控制項工作區的大小。

(繼承來源 Control)
SetDataBinding(Object, String)

設定執行階段時的 DataSourceDataMember 屬性。

SetStyle(ControlStyles, Boolean)

將指定的 ControlStyles 旗標設定為 truefalse

(繼承來源 Control)
SetTopLevel(Boolean)

將控制項設定為最上層控制項。

(繼承來源 Control)
SetVisibleCore(Boolean)

將控制項設定為指定的可見狀態。

(繼承來源 Control)
ShouldSerializeAlternatingBackColor()

指示是否應該保存 AlternatingBackColor 屬性。

ShouldSerializeBackgroundColor()

指示是否應該保存 BackgroundColor 屬性。

ShouldSerializeCaptionBackColor()

取得值,表示是否應該保存 CaptionBackColor 屬性。

ShouldSerializeCaptionForeColor()

取得值,表示是否應該保存 CaptionForeColor 屬性。

ShouldSerializeGridLineColor()

指示是否應該保存 GridLineColor 屬性。

ShouldSerializeHeaderBackColor()

指示是否應該保存 HeaderBackColor 屬性。

ShouldSerializeHeaderFont()

指示是否應該保存 HeaderFont 屬性。

ShouldSerializeHeaderForeColor()

指示是否應該保存 HeaderForeColor 屬性。

ShouldSerializeLinkHoverColor()

指示是否應該保存 LinkHoverColor 屬性。

ShouldSerializeParentRowsBackColor()

指示是否應該保存 ParentRowsBackColor 屬性。

ShouldSerializeParentRowsForeColor()

指示是否應該保存 ParentRowsForeColor 屬性。

ShouldSerializePreferredRowHeight()

指示是否應該保存 PreferredRowHeight 屬性。

ShouldSerializeSelectionBackColor()

指示是否應該保存 SelectionBackColor 屬性。

ShouldSerializeSelectionForeColor()

指示是否應該保存 SelectionForeColor 屬性。

Show()

對使用者顯示控制項。

(繼承來源 Control)
SizeFromClientSize(Size)

從控制項的工作區之高度和寬度判斷整個控制項的大小。

(繼承來源 Control)
SubObjectsSiteChange(Boolean)

從容器 (Container) 加入或移除 DataGridTableStyle 物件,而這個容器是與 DataGrid 產生關聯。

SuspendLayout()

暫停控制項的配置邏輯。

(繼承來源 Control)
ToString()

傳回任何包含 Component 名稱的 String。 不應覆寫此方法。

(繼承來源 Component)
UnSelect(Int32)

取消選取指定的資料列。

Update()

使控制項重繪其工作區內的失效區域。

(繼承來源 Control)
UpdateBounds()

以目前大小和位置更新控制項的範圍。

(繼承來源 Control)
UpdateBounds(Int32, Int32, Int32, Int32)

以指定的大小和位置更新控制項的範圍。

(繼承來源 Control)
UpdateBounds(Int32, Int32, Int32, Int32, Int32, Int32)

以指定的大小、位置和工作區大小更新控制項的範圍。

(繼承來源 Control)
UpdateStyles()

強制重新套用指派的樣式至控制項。

(繼承來源 Control)
UpdateZOrder()

以控制項的父控制項疊置順序更新控制項。

(繼承來源 Control)
WndProc(Message)

處理 Windows 訊息。

(繼承來源 Control)

事件

AllowNavigationChanged

發生於 AllowNavigation 屬性變更時。

AutoSizeChanged

這個事件與這個類別無關。

(繼承來源 Control)
BackButtonClick

發生於按一下子資料表的 Back 按鈕時。

BackColorChanged

發生於 BackColor 屬性的值變更時。

(繼承來源 Control)
BackgroundColorChanged

發生於 BackgroundColor 變更時。

BackgroundImageChanged

發生於 BackgroundImage 屬性的值變更時。

BackgroundImageLayoutChanged

發生於 BackgroundImageLayout 屬性的值變更時。

BackgroundImageLayoutChanged

發生於 BackgroundImageLayout 屬性變更時。

(繼承來源 Control)
BindingContextChanged

發生於 BindingContext 屬性的值變更時。

(繼承來源 Control)
BorderStyleChanged

發生於 BorderStyle 變更時。

CaptionVisibleChanged

發生於 CaptionVisible 屬性變更時。

CausesValidationChanged

發生於 CausesValidation 屬性的值變更時。

(繼承來源 Control)
ChangeUICues

發生於焦點或鍵盤使用者介面 (UI) 提示變更時。

(繼承來源 Control)
Click

發生於按下控制項時。

(繼承來源 Control)
ClientSizeChanged

發生於 ClientSize 屬性的值變更時。

(繼承來源 Control)
ContextMenuChanged

發生於 ContextMenu 屬性的值變更時。

(繼承來源 Control)
ContextMenuStripChanged

發生於 ContextMenuStrip 屬性的值變更時。

(繼承來源 Control)
ControlAdded

發生於加入新控制項至 Control.ControlCollection 時。

(繼承來源 Control)
ControlRemoved

發生於從 Control.ControlCollection 移除控制項時。

(繼承來源 Control)
CurrentCellChanged

發生於 CurrentCell 屬性變更時。

CursorChanged

發生於 Cursor 屬性的值變更時。

DataContextChanged

發生於 DataContext 屬性的值變更時。

(繼承來源 Control)
DataSourceChanged

發生於 DataSource 屬性值變更時。

Disposed

Dispose() 方法的呼叫處置元件時,就會發生。

(繼承來源 Component)
DockChanged

發生於 Dock 屬性的值變更時。

(繼承來源 Control)
DoubleClick

發生於按兩下控制項時。

(繼承來源 Control)
DpiChangedAfterParent

發生於某個控制項的父控制項或表單已變更之後,以程式設計方式變更其 DPI 設定時。

(繼承來源 Control)
DpiChangedBeforeParent

發生於某個控制項的父控制項或表單發生 DPI 變更事件之前,以程式設計方式變更其 DPI 設定時。

(繼承來源 Control)
DragDrop

發生於拖放作業完成時。

(繼承來源 Control)
DragEnter

發生於將物件拖曳至控制項邊框時。

(繼承來源 Control)
DragLeave

發生於將物件拖出控制項界限時。

(繼承來源 Control)
DragOver

發生於將物件拖曳至控制項邊框上方時。

(繼承來源 Control)
EnabledChanged

發生於 Enabled 屬性值變更時。

(繼承來源 Control)
Enter

發生於輸入控制項時。

(繼承來源 Control)
FlatModeChanged

發生於 FlatMode 變更時。

FontChanged

發生在 Font 屬性值變更時。

(繼承來源 Control)
ForeColorChanged

發生在 ForeColor 屬性值變更時。

(繼承來源 Control)
GiveFeedback

發生於拖曳作業時。

(繼承來源 Control)
GotFocus

發生於控制項取得焦點時。

(繼承來源 Control)
HandleCreated

發生於為控制項建立控制代碼時。

(繼承來源 Control)
HandleDestroyed

發生於終結控制項的控制代碼時。

(繼承來源 Control)
HelpRequested

發生於使用者要求控制項的說明時。

(繼承來源 Control)
ImeModeChanged

發生於 ImeMode 屬性變更時。

(繼承來源 Control)
Invalidated

發生於控制項的顯示需要重新繪製時。

(繼承來源 Control)
KeyDown

發生於按下按鍵且焦點在控制項時。

(繼承來源 Control)
KeyPress

發生於 控制項有焦點,並按下字元空格鍵或退格鍵時。

(繼承來源 Control)
KeyUp

發生於放開按鍵且焦點在控制項時。

(繼承來源 Control)
Layout

發生於控制項應重新調整其子控制項位置時。

(繼承來源 Control)
Leave

發生於輸入焦點離開控制項時。

(繼承來源 Control)
LocationChanged

發生於 Location 屬性值變更時。

(繼承來源 Control)
LostFocus

發生於控制項遺失焦點時。

(繼承來源 Control)
MarginChanged

發生於控制項的邊界變更時。

(繼承來源 Control)
MouseCaptureChanged

發生於控制項遺失滑鼠捕捉時。

(繼承來源 Control)
MouseClick

發生於使用滑鼠按一下控制項時。

(繼承來源 Control)
MouseDoubleClick

發生於以滑鼠按兩下控制項時。

(繼承來源 Control)
MouseDown

發生於滑鼠指標位於控制項上並按下滑鼠按鍵時。

(繼承來源 Control)
MouseEnter

發生於滑鼠指標進入控制項時。

(繼承來源 Control)
MouseHover

發生於滑鼠指標停留在控制項上時。

(繼承來源 Control)
MouseLeave

發生於滑鼠指標離開控制項時。

(繼承來源 Control)
MouseMove

發生於滑鼠指標移至控制項上時。

(繼承來源 Control)
MouseUp

發生於滑鼠指標位於控制項上並放開滑鼠按鍵時。

(繼承來源 Control)
MouseWheel

發生於滑鼠滾輪移動且焦點在控制項時。

(繼承來源 Control)
Move

發生於控制項移動時。

(繼承來源 Control)
Navigate

發生於使用者巡覽至新的資料表時。

PaddingChanged

發生於控制項的邊框間距變更時。

(繼承來源 Control)
Paint

發生於重繪控制項時。

(繼承來源 Control)
ParentChanged

發生在 Parent 屬性值變更時。

(繼承來源 Control)
ParentRowsLabelStyleChanged

發生於父資料列標籤樣式變更時。

ParentRowsVisibleChanged

發生在 ParentRowsVisible 屬性值變更時。

PreviewKeyDown

發生於焦點位於這個控制項上時並按下鍵盤按鍵的 KeyDown 事件之前。

(繼承來源 Control)
QueryAccessibilityHelp

發生於 AccessibleObject 為協助工具應用程式提供說明時。

(繼承來源 Control)
QueryContinueDrag

發生於拖放作業時,讓拖曳來源能夠決定是否應取消拖放作業。

(繼承來源 Control)
ReadOnlyChanged

發生在 ReadOnly 屬性值變更時。

RegionChanged

發生於 Region 屬性的值變更時。

(繼承來源 Control)
Resize

發生於重設控制項大小時。

(繼承來源 Control)
RightToLeftChanged

發生在 RightToLeft 屬性值變更時。

(繼承來源 Control)
RowHeaderClick

發生於按一下資料列標頭時。

Scroll

發生於使用者捲動 DataGrid 控制項時。

ShowParentDetailsButtonClick

發生於按一下 ShowParentDetails 按鈕時。

SizeChanged

發生在 Size 屬性值變更時。

(繼承來源 Control)
StyleChanged

發生於控制項樣式變更時。

(繼承來源 Control)
SystemColorsChanged

發生於系統色彩變更時。

(繼承來源 Control)
TabIndexChanged

發生在 TabIndex 屬性值變更時。

(繼承來源 Control)
TabStopChanged

發生在 TabStop 屬性值變更時。

(繼承來源 Control)
TextChanged

發生於 Text 屬性的值變更時。

Validated

發生於控制項完成驗證時。

(繼承來源 Control)
Validating

發生於驗證控制項時。

(繼承來源 Control)
VisibleChanged

發生在 Visible 屬性值變更時。

(繼承來源 Control)

明確介面實作

IDropTarget.OnDragDrop(DragEventArgs)

引發 DragDrop 事件。

(繼承來源 Control)
IDropTarget.OnDragEnter(DragEventArgs)

引發 DragEnter 事件。

(繼承來源 Control)
IDropTarget.OnDragLeave(EventArgs)

引發 DragLeave 事件。

(繼承來源 Control)
IDropTarget.OnDragOver(DragEventArgs)

引發 DragOver 事件。

(繼承來源 Control)

適用於

另請參閱