DataGrid.SetDataBinding(Object, String) Metod

Definition

DataSource Anger egenskaperna och DataMember vid körning.

public:
 void SetDataBinding(System::Object ^ dataSource, System::String ^ dataMember);
public void SetDataBinding(object dataSource, string dataMember);
member this.SetDataBinding : obj * string -> unit
Public Sub SetDataBinding (dataSource As Object, dataMember As String)

Parametrar

dataSource
Object

Datakällan för DataGrid kontrollen.

dataMember
String

Strängen DataMember som anger tabellen som ska bindas till i objektet som returneras av egenskapen DataSource .

Undantag

Ett eller flera av argumenten är ogiltiga.

Argumentet dataSource är null.

Exempel

I följande kodexempel anges och till , DataSourcerespektive i .DataMemberDataSetDataTableDataSet

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.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 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

Kommentarer

Du måste använda SetDataBinding metoden vid körning för att återställa DataSource egenskapen.

Mer information om hur du anger en giltig datakälla finns i DataSource egenskapen.

Du kan skapa ett rutnät som gör det möjligt för användare att redigera data, men hindrar dem från att lägga till nya rader med hjälp av en DataView som datakälla och ställa in AllowNew egenskapen på false. DataSource När är en DataView eller DataTableanger du DataMember till en tom sträng ("").

Gäller för

Se även