Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Legt die DataSource-Eigenschaft und die DataMember-Eigenschaft zur Laufzeit fest.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Sub SetDataBinding ( _
dataSource As Object, _
dataMember As String _
)
'Usage
Dim instance As DataGrid
Dim dataSource As Object
Dim dataMember As String
instance.SetDataBinding(dataSource, dataMember)
public void SetDataBinding (
Object dataSource,
string dataMember
)
public:
void SetDataBinding (
Object^ dataSource,
String^ dataMember
)
public void SetDataBinding (
Object dataSource,
String dataMember
)
public function SetDataBinding (
dataSource : Object,
dataMember : String
)
Parameter
- dataSource
Die Datenquelle für das System.Windows.Forms.DataGrid-Steuerelement.
- dataMember
Die DataMember-Zeichenfolge, die die Tabelle, an die die Bindung erfolgen soll, in dem durch die DataSource-Eigenschaft zurückgegebenen Objekt angibt.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
Ein oder mehrere Argumente sind ungültig. |
|
Das dataSource-Argument ist NULL (Nothing in Visual Basic). |
Hinweise
Zum Zurücksetzen der DataSource-Eigenschaft muss die SetDataBinding-Methode zur Laufzeit verwendet werden.
Weitere Informationen über das Festlegen einer gültigen Datenquelle finden Sie unter der DataSource-Eigenschaft.
Sie können ein Datenblatt erstellen, in dem Daten bearbeitet, aber keine neuen Zeilen hinzufügt werden können, indem Sie eine DataView als Datenquelle verwenden und die AllowNew-Eigenschaft auf false festlegen. Wenn es sich bei der DataSource um eine DataView oder eine DataTable handelt, legen Sie den DataMember auf eine leere Zeichenfolge ("") fest.
Beispiel
Im folgenden Codebeispiel werden die DataSource und der DataMember auf ein DataSet festgelegt, und im DataSet wird eine DataTable festgelegt.
Private Sub BindControls()
' Create a DataSet named SuppliersProducts.
Dim SuppliersProducts As New DataSet("SuppliersProducts")
' Adds two DataTable objects, Suppliers and Products.
SuppliersProducts.Tables.Add(New DataTable("Suppliers"))
SuppliersProducts.Tables.Add(New DataTable("Products"))
' Insert code to add DataColumn objects.
' Insert code to fill tables with columns and data.
' Binds the DataGrid to the DataSet, displaying the Suppliers table.
dataGrid1.SetDataBinding(SuppliersProducts, "Suppliers")
End Sub 'BindControls
private void BindControls(){
// Creates a DataSet named SuppliersProducts.
DataSet SuppliersProducts = new DataSet("SuppliersProducts");
// Adds two DataTable objects, Suppliers and Products.
SuppliersProducts.Tables.Add(new DataTable("Suppliers"));
SuppliersProducts.Tables.Add(new DataTable("Products"));
// Insert code to add DataColumn objects.
// Insert code to fill tables with columns and data.
// Binds the DataGrid to the DataSet, displaying the Suppliers table.
dataGrid1.SetDataBinding(SuppliersProducts, "Suppliers");
}
private:
void BindControls()
{
// Creates a DataSet named SuppliersProducts.
DataSet^ SuppliersProducts = gcnew DataSet( "SuppliersProducts" );
// Adds two DataTable objects, Suppliers and Products.
SuppliersProducts->Tables->Add( gcnew DataTable( "Suppliers" ) );
SuppliersProducts->Tables->Add( gcnew DataTable( "Products" ) );
// Insert code to add DataColumn objects.
// Insert code to fill tables with columns and data.
// Binds the DataGrid to the DataSet, displaying the Suppliers table.
dataGrid1->SetDataBinding( SuppliersProducts, "Suppliers" );
}
private void BindControls()
{
// Creates a DataSet named SuppliersProducts.
DataSet suppliersProducts = new DataSet("SuppliersProducts");
// Adds two DataTable objects, Suppliers and Products.
suppliersProducts.get_Tables().Add(new DataTable("Suppliers"));
suppliersProducts.get_Tables().Add(new DataTable("Products"));
// Insert code to add DataColumn objects.
// Insert code to fill tables with columns and data.
// Binds the DataGrid to the DataSet, displaying the Suppliers table.
dataGrid1.SetDataBinding(suppliersProducts, "Suppliers");
} //BindControls
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
DataGrid-Klasse
DataGrid-Member
System.Windows.Forms-Namespace
DataMember
DataSource
DataSet
DataView