DataGrid 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
DataGrid is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use DataGridView instead.
在可滚动网格中显示 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
[System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.ComponentModel.Browsable(false)]
[System.Obsolete("`DataGrid` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `DataGridView` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
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
[<System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")>]
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.ComponentModel.Browsable(false)>]
[<System.Obsolete("`DataGrid` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `DataGridView` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
type DataGrid = class
inherit Control
interface ISupportInitialize
interface IDataGridEditingService
Public Class DataGrid
Inherits Control
Implements IDataGridEditingService, ISupportInitialize
- 继承
- 属性
- 实现
示例
下面的代码示例创建一个 Windows 窗体,一个包含两DataTable个DataSet对象,一个关联这两个DataRelation表。 若要显示数据,System.Windows.Forms.DataGrid控件随后通过该方法绑定到DataSetSetDataBinding该控件。 窗体上的按钮通过创建两个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 类似网页链接的子表链接。 可以单击指向子表的链接。 显示子表时,标题中会显示一个后退按钮,可以单击该按钮以导航回父表。 父行中的数据显示在标题下方和列标题上方。 可以通过单击后退按钮右侧的按钮来隐藏父行信息。
若要在System.Windows.Forms.DataGrid运行时显示表,请使用SetDataBinding该方法将和DataMember属性设置为DataSource有效的数据源。 以下数据源有效:
执行 DataTable 操作
执行 DataView 操作
执行 DataSet 操作
执行 DataViewManager 操作
单个维度数组
实现 IListSource 接口的任何组件
实现 IList 接口的任何组件
有关类的详细信息 DataSet ,请参阅 DataSets、DataTables 和 DataViews。
可以创建一个网格,使用户能够编辑数据,但阻止他们添加新行,方法是使用DataView数据源并将属性false设置为 AllowNew 。
数据源由 BindingManagerBase 对象进一步管理。 对于数据源中的每个表,可以从窗体的BindingContext表返回一个 BindingManagerBase 。 例如,可以通过返回关联的 BindingManagerBase 对象的属性来确定数据源包含的 Count 行数。
若要验证数据,请使用表示数据及其事件的基础对象。 例如,如果数据来自某个 DataTable 值 DataSet,请使用 ColumnChanging 和 RowChanging 事件。
注释
由于可以自定义列数(通过添加或删除成员GridColumnStylesCollection),行可以按列进行排序,RowNumberColumnNumber因此无法保证属性值与列DataTable的对应DataRow和DataColumn索引。 因此,应避免在事件中使用 Validating 这些属性来验证数据。
若要确定选择哪个单元格,请使用 CurrentCell 该属性。 使用 Item[] 属性更改任何单元格的值,该属性可以获取单元格的行索引和列索引或单个 DataGridCell单元格。 CurrentCellChanged监视事件,以检测用户何时选择另一个单元格。
若要确定用户单击的控件的哪个部分,请使用 HitTest 事件 MouseDown 中的方法。 该方法 HitTest 返回一个 DataGrid.HitTestInfo 对象,该对象包含单击区域的行和列。
若要在运行时管理控件的外观,可用于设置颜色和题注属性的多个属性,包括 CaptionForeColor、 CaptionBackColor和 CaptionFont等。
可以通过创建 DataGridTableStyle 对象并将其添加到 GridTableStylesCollection通过 TableStyles 属性访问的对象来进一步修改显示的网格(或网格)的外观。 例如,如果DataSource设置为包含三个对象,则可以向集合中添加三DataTableDataGridTableStyle个DataSet对象,每个表各有一个对象。 若要将每个DataGridTableStyle对象与一个DataTable对象同步,请将DataGridTableStyleMappingName该对象的集合设置为 TableName 。DataTable 有关绑定到对象数组的详细信息,请参阅该 DataGridTableStyle.MappingName 属性。
若要创建自定义表视图,请创建某个或类的DataGridTextBoxColumn实例,并将对象添加到GridTableStylesCollection通过属性访问的对象TableStyles。DataGridBoolColumn 这两个类都继承自 DataGridColumnStyle. 对于每个列样式,请将 MappingName 要显示在网格中的列的列设置为 ColumnName 。 若要隐藏列,请将其 MappingName 设置为非有效 ColumnName列。
若要设置列文本的格式,请将FormatDataGridTextBoxColumn格式设置类型和自定义日期和时间格式字符串中找到的值之一的属性。
若要绑定到 DataGrid 强类型对象数组,对象类型必须包含公共属性。 若要创建 DataGridTableStyle 显示数组的属性,请将 DataGridTableStyle.MappingName 属性设置为 typename[] 由 typename 对象类型的名称替换的位置。 另请注意,该 MappingName 属性区分大小写;类型名称必须完全匹配。 有关示例, MappingName 请参阅该属性。
还可以绑定到 DataGrid . ArrayList. 其特征 ArrayList 是它可以包含多个类型的对象,但 DataGrid 当列表中的所有项都与第一项具有相同的类型时,它只能绑定到此类列表。 这意味着所有对象必须具有相同的类型,或者它们必须继承自与列表中的第一项相同的类。 例如,如果列表中的第一项为 a Control,则第二项可以是一个 TextBox (继承自 Control)。 另一方面,如果第一项是一个,第二个 TextBox对象不能是一个 Control。 此外,绑定 ArrayList 项时必须包含项。 空 ArrayList 将导致空网格。 此外,这些 ArrayList 对象必须包含公共属性。 绑定到 an ArrayList时,将MappingNameDataGridTableStyle“ArrayList”(类型名称)设置为“ArrayList”。
对于每个 DataGridTableStyle属性,可以设置替代控件设置 System.Windows.Forms.DataGrid 的颜色和标题属性。 但是,如果未设置这些属性,则默认使用控件的设置。 属性可以重写 DataGridTableStyle 以下属性:
若要自定义各个列的外观,请将对象添加到DataGridColumnStyleGridColumnStylesCollection通过GridColumnStyles每个DataGridTableStyle列的属性访问的对象。 若要将每个DataGridColumnStyle项与其中DataTable一个DataColumn同步,请MappingNameColumnName设置为 aDataColumn。 构造时 DataGridColumnStyle,还可以设置一个格式字符串,指定列如何显示数据。 例如,可以指定列使用短日期格式显示表中所包含的日期。
注意
始终创建 DataGridColumnStyle 对象并将其添加到 GridColumnStylesCollection 将对象添加到 DataGridTableStyle 之前 GridTableStylesCollection。 向集合中添加具有有效MappingName值的空DataGridTableStyle时,DataGridColumnStyle会自动为你生成对象。 因此,如果尝试将具有重复
注释
控件 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 |
已过时.
获取或设置网格的偶数行的背景色。 |
| BackColor |
已过时.
获取或设置控件的背景色。 (继承自 Control) |
| BackgroundColor |
已过时.
获取或设置网格的非行区域的颜色。 |
| BackgroundImage |
已过时.
此成员对此控件没有意义。 |
| BackgroundImageLayout |
已过时.
此成员对此控件没有意义。 |
| BindingContext |
已过时.
获取或设置 BindingContext 控件。 (继承自 Control) |
| BorderStyle |
已过时.
获取或设置网格的边框样式。 |
| Bottom |
已过时.
获取控件的下边缘与其容器工作区的上边缘之间的距离(以像素为单位)。 (继承自 Control) |
| Bounds |
已过时.
获取或设置控件的大小和位置,包括其相对于父控件的非client 元素(以像素为单位)。 (继承自 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 |
已过时.
IContainer获取包含 .Component (继承自 Component) |
| ContainsFocus |
已过时.
获取一个值,该值指示控件或其子控件之一当前是否具有输入焦点。 (继承自 Control) |
| ContextMenu |
已过时.
获取或设置与控件关联的快捷菜单。 (继承自 Control) |
| ContextMenuStrip |
已过时.
获取或设置 ContextMenuStrip 与此控件关联的值。 (继承自 Control) |
| Controls |
已过时.
获取控件中包含的控件的集合。 (继承自 Control) |
| Created |
已过时.
获取一个值,该值指示是否已创建控件。 (继承自 Control) |
| CreateParams |
已过时.
获取创建控件句柄时所需的创建参数。 (继承自 Control) |
| CurrentCell |
已过时.
获取或设置具有焦点的单元格。 在设计时不可用。 |
| CurrentRowIndex |
已过时.
获取或设置当前具有焦点的行的索引。 |
| Cursor |
已过时.
此成员对此控件没有意义。 |
| DataBindings |
已过时.
获取控件的数据绑定。 (继承自 Control) |
| DataContext |
已过时.
获取或设置用于数据绑定的数据上下文。 这是一个环境属性。 (继承自 Control) |
| DataMember |
已过时.
获取或设置控件显示DataSourceDataGrid网格的特定列表。 |
| DataSource |
已过时.
获取或设置网格显示其数据的数据源。 |
| DefaultCursor |
已过时.
获取或设置控件的默认游标。 (继承自 Control) |
| DefaultImeMode |
已过时.
获取控件支持的默认输入法编辑器 (IME) 模式。 (继承自 Control) |
| DefaultMargin |
已过时.
获取默认情况下在控件之间指定的空间(以像素为单位)。 (继承自 Control) |
| DefaultMaximumSize |
已过时.
获取指定为控件的默认最大大小的长度和高度(以像素为单位)。 (继承自 Control) |
| DefaultMinimumSize |
已过时.
获取指定为控件的默认最小大小的长度和高度(以像素为单位)。 (继承自 Control) |
| DefaultPadding |
已过时.
获取控件内容的默认内部间距(以像素为单位)。 (继承自 Control) |
| DefaultSize |
已过时.
获取控件的默认大小。 |
| DefaultSize |
已过时.
获取控件的默认大小。 (继承自 Control) |
| 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 。 |
| ForeColor |
已过时.
获取或设置控件的前景色。 (继承自 Control) |
| GridLineColor |
已过时.
获取或设置网格线的颜色。 |
| GridLineStyle |
已过时.
获取或设置网格的线条样式。 |
| Handle |
已过时.
获取控件绑定到的窗口句柄。 (继承自 Control) |
| HasChildren |
已过时.
获取一个值,该值指示控件是否包含一个或多个子控件。 (继承自 Control) |
| HeaderBackColor |
已过时.
获取或设置所有行标题和列标题的背景色。 |
| HeaderFont |
已过时.
获取或设置用于列标题的字体。 |
| HeaderForeColor |
已过时.
获取或设置标头的前景色。 |
| Height |
已过时.
获取或设置控件的高度。 (继承自 Control) |
| HorizScrollBar |
已过时.
获取网格的水平滚动条。 |
| ImeMode |
已过时.
获取或设置控件的输入法编辑器 (IME) 模式。 (继承自 Control) |
| ImeModeBase |
已过时.
获取或设置控件的 IME 模式。 (继承自 Control) |
| InvokeRequired |
已过时.
获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用调用方法,因为调用方与创建控件的线程不同。 (继承自 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 |
已过时.
获取或设置控件的站点。 |
| Site |
已过时.
获取或设置控件的站点。 (继承自 Control) |
| 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) |
方法
活动
| 名称 | 说明 |
|---|---|
| AllowNavigationChanged |
已过时.
属性 AllowNavigation 已更改时发生。 |
| AutoSizeChanged |
已过时.
此事件与此类无关。 (继承自 Control) |
| BackButtonClick |
已过时.
单击子表上的按钮时 |
| BackColorChanged |
已过时.
当 BackColor 属性的值更改时发生。 (继承自 Control) |
| BackgroundColorChanged |
已过时.
更改 BackgroundColor 后发生。 |
| BackgroundImageChanged |
已过时.
当 BackgroundImage 属性的值更改时发生。 |
| BackgroundImageLayoutChanged |
已过时.
当 BackgroundImageLayout 属性的值更改时发生。 |
| 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 |
已过时.
单击按钮时 |
| 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) |