DataGrid 构造函数

定义

初始化 DataGrid 类的新实例。

public:
 DataGrid();
public DataGrid ();
Public Sub New ()

示例

下面的代码示例创建一个新 System.Windows.Forms.DataGrid 代码,并使用 SetDataBinding 该方法设置 DataSourceDataMember 属性。

' This object variable must go in the Declarations section:
Private DataGrid1 As DataGrid
 
Private Sub CreateDataGrid()
   ' Initialize a new DataGrid control.
   me.Datagrid1 = New DataGrid
   
   Dim myDataSet As DataSet = New DataSet("myDataSet")
   Dim myDataTable As DataTable = New DataTable("Customers")
   myDataSet.Tables.Add(myDataTable)
   ' Insert code to populate the DataTable with rows.
   ' Set the DataSource and DataMember of the DataGrid control.
   DataGrid1.SetDataBinding(myDataSet, "Customers")
End Sub

注解

若要填充新创建的 System.Windows.Forms.DataGrid 控件,请将 DataSource 属性设置为有效的源,例如 DataViewDataSetDataViewManager

适用于

另请参阅