Export (0) Print
Expand All

DataGrid Constructor

Initializes a new instance of the System.Windows.Forms.DataGrid class.

[Visual Basic]
Public Sub New()
[C#]
public DataGrid();
[C++]
public: DataGrid();
[JScript]
public function DataGrid();

Remarks

To populate a newly created System.Windows.Forms.DataGrid control, set the DataSource property to a valid source, such as a DataView, DataSet, or DataViewManager.

Example

[Visual Basic] The following example creates a new System.Windows.Forms.DataGrid and uses the SetDataBinding method to set the DataSource and DataMember properties.

[Visual Basic] 
' 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

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataGrid Class | DataGrid Members | System.Windows.Forms Namespace | DataColumnCollection | DataColumn | DataMember | DataView | DataTable | GridTableStylesCollection

Show:
© 2014 Microsoft