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 窗体,一个包含两DataTableDataSet 对象的 ,以及一个关联这两个DataRelation表的 。 为了显示数据,System.Windows.Forms.DataGrid控件随后通过 SetDataBinding 方法绑定到 DataSet 。 窗体上的按钮通过创建两DataGridTableStyle个 对象并将每个对象的 设置为MappingName其中一DataTableTableName 对象的 来更改网格的外观。 该示例还包含 事件中的 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

可以创建一个网格,使用户能够编辑数据,但通过将 用作数据源并将 属性设置为 AllowNewfalse来阻止他们添加新行DataView

数据源由 BindingManagerBase 对象进一步管理。 对于数据源中的每个表, BindingManagerBase 可以从窗体的 BindingContext返回 。 例如,可以通过返回关联的 BindingManagerBase 对象的 属性来确定数据源包含的 Count 行数。

若要验证数据,请使用表示数据及其事件的基础对象。 例如,如果数据来自 DataTable 中的 DataSet,请使用 ColumnChangingRowChanging 事件。

注意

由于可以通过添加或删除 () 的成员GridColumnStylesCollection来自定义列数,并且行可以按列排序,RowNumber因此无法保证 和 ColumnNumber 属性值与 中的 DataTableDataColumn 索引相对应DataRow。 因此,应避免在 事件中 Validating 使用这些属性来验证数据。

若要确定选择哪个单元格,请使用 CurrentCell 属性。 使用 Item[] 属性更改任何单元格的值,该属性可以采用单元格的行索引和列索引,也可以采用单个 DataGridCell。 监视事件以 CurrentCellChanged 检测用户选择另一个单元格时。

若要确定用户单击的控件的哪个部分,请在 事件中使用 HitTestMouseDown 方法。 方法 HitTest 返回一个 DataGrid.HitTestInfo 对象,该对象包含单击区域的行和列。

若要在运行时管理控件的外观,可以使用多个属性来设置颜色和描述文字属性,包括 CaptionForeColorCaptionBackColorCaptionFont、 等。

可以进一步修改显示网格 (或网格) 的外观,方法是创建 DataGridTableStyle 对象并将其添加到 GridTableStylesCollection可通过 属性访问 TableStyles 的 。 例如,如果 DataSource 设置为包含三DataTable个 对象的 ,则可以向集合添加三DataGridTableStyleDataSet对象,每个表一个对象。 若要将每个 DataGridTableStyle 对象与 同步,DataTable请将 MappingNameDataGridTableStyle 设置为 TableName 的 。DataTable 有关绑定到对象数组的详细信息,请参阅 DataGridTableStyle.MappingName 属性。

若要创建表的自定义视图,请创建 或 类的DataGridTextBoxColumn实例,并将 对象GridTableStylesCollection添加到通过 属性访问的 TableStylesDataGridBoolColumn 这两个类均从 DataGridColumnStyle 继承。 对于每个列样式,请将 设置为MappingNameColumnName要在网格中显示的列的 。 若要隐藏列,请将其 MappingName 设置为有效 ColumnName以外的其他值。

若要设置列文本的格式,请将 的 DataGridTextBoxColumn 属性设置为Format格式设置类型和自定义日期和时间格式字符串中找到的值之一。

若要将 绑定到 DataGrid 对象的强类型数组,对象类型必须包含公共属性。 若要创建 DataGridTableStyle 显示数组的 ,请将 DataGridTableStyle.MappingName 属性 typename[] 设置为 ,其中 typename 替换为对象类型的名称。 另请注意, MappingName 属性区分大小写;类型名称必须完全匹配。 有关示例, MappingName 请参阅 属性。

还可以将 绑定到 DataGridArrayList。 的 ArrayList 一个功能是它可以包含多个类型的 对象,但 DataGrid 仅当列表中的所有项都与第一个项属于同一类型时,才能绑定到此类列表。 这意味着所有对象必须属于同一类型,或者它们必须继承自与列表中的第一项相同的类。 例如,如果列表中的第一项是 , Control则第二项 TextBox 可能是继承自 Control) 的 (。 另一方面,如果第一项 TextBox为 ,则第二个对象不能为 Control。 此外, ArrayList 绑定时必须包含项。 空 ArrayList 将导致空网格。 此外,中的 ArrayList 对象必须包含公共属性。 绑定到 时ArrayList,将 的 DataGridTableStyle 设置为MappingName“ArrayList”, (类型名称) 。

对于每个 DataGridTableStyle,可以设置颜色和描述文字属性来替代控件的设置System.Windows.Forms.DataGrid。 但是,如果未设置这些属性,则默认使用控件的设置。 以下属性可由属性重写 DataGridTableStyle

若要自定义各个列的外观,请将 对象添加到 DataGridColumnStyleGridColumnStylesCollection,该对象可通过 GridColumnStyles 每个 DataGridTableStyle的 属性进行访问。 若要将 每个 DataGridColumnStyleDataColumn 中的 DataTable同步, MappingName 请将 设置为 ColumnNameDataColumn。 构造 DataGridColumnStyle时,还可以设置格式字符串,用于指定列显示数据的方式。 例如,可以指定列使用短日期格式来显示表中包含的日期。

注意

在将 对象添加到 之前,始终创建 DataGridColumnStyle 对象并将其添加到 DataGridTableStyleGridTableStylesCollectionGridColumnStylesCollection 将具有有效MappingName值的空DataGridTableStyle添加到集合时,DataGridColumnStyle将自动生成对象。 因此,如果尝试将具有重复MappingName值的新DataGridColumnStyle对象添加到 ,GridColumnStylesCollection将引发异常。

注意

DataGridView 控件取代了 DataGrid 控件并添加了功能;但是,可以选择保留 DataGrid 控件以实现向后兼容并供将来使用。 有关详细信息,请参阅 Windows 窗体 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

获取控件下边缘与其容器的工作区上边缘之间的距离(以像素为单位)。

(继承自 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

获取或设置具有焦点的单元格。 设计时不可用。

CurrentRowIndex

获取或设置当前具有焦点的行的索引。

Cursor

此成员对于此控件无意义。

DataBindings

为该控件获取数据绑定。

(继承自 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

获取或设置一个值,该值指示此控件是否应使用辅助缓冲区重绘其图面,以减少或避免闪烁。

(继承自 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

获取或设置控件左边缘与其容器的工作区左边缘之间的距离(以像素为单位)。

(继承自 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

获取控件右边缘与其容器的工作区左边缘之间的距离(以像素为单位)。

(继承自 Control)
RightToLeft

获取或设置一个值,该值指示是否将控件的元素对齐以支持使用从右向左的字体的区域设置。

(继承自 Control)
RowHeadersVisible

获取或设置一个值,该值指定行标题是否可见。

RowHeaderWidth

获取或设置行标题宽度。

ScaleChildren

获取一个值,该值确定子控件的缩放。

(继承自 Control)
SelectionBackColor

获取或设置选定行的背景色。

SelectionForeColor

获取或设置选定行的前景色。

ShowFocusCues

获取一个值,该值指示控件是否应显示聚焦框。

(继承自 Control)
ShowKeyboardCues

获取一个值,该值指示用户界面是否处于适当的状态以显示或隐藏键盘快捷键。

(继承自 Control)
Site

获取或设置控件的站点。

Size

获取或设置控件的高度和宽度。

(继承自 Control)
TabIndex

获取或设置控件在其容器内的 Tab 键顺序。

(继承自 Control)
TableStyles

获取网格的 DataGridTableStyle 对象的集合。

TabStop

获取或设置一个值,该值指示用户能否使用 Tab 键将焦点放到该控件上。

(继承自 Control)
Tag

获取或设置包含有关控件的数据的对象。

(继承自 Control)
Text

此成员对于此控件无意义。

Top

获取或设置控件上边缘与其容器的工作区上边缘之间的距离(以像素为单位)。

(继承自 Control)
TopLevelControl

获取没有另一个 Windows 窗体控件作为其父级的父控件。 通常,这是控件所在的最外面的 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()

将控件带到 Z 顺序的前面。

(继承自 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)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
DefWndProc(Message)

向默认窗口过程发送指定消息。

(继承自 Control)
DestroyHandle()

毁坏与该控件关联的句柄。

(继承自 Control)
Dispose()

释放由 Component 使用的所有资源。

(继承自 Component)
Dispose(Boolean)

处置由 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()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetNextControl(Control, Boolean)

按照子控件的 Tab 键顺序向前或向后检索下一个控件。

(继承自 Control)
GetOutputTextDelimiter()

当行内容被复制到剪贴板时,获取作为列间的分隔符的字符串。

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)

将指定屏幕点的位置计算成工作区坐标。

(继承自 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)

激活子控件。 还可以指定从中选择控件的 Tab 键顺序的方向。

(继承自 Control)
Select(Int32)

选择指定行。

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

激活下一个控件。

(继承自 Control)
SendToBack()

将控件发送到 Z 顺序的后面。

(继承自 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)

从与 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()

按控件的父级的 Z 顺序更新控件。

(继承自 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 更改后,以编程方式更改控件的 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)

适用于

另请参阅