Condividi tramite


DataGrid.SetDataBinding(Object, String) Metodo

Definizione

Imposta le DataSource proprietà e DataMember in fase di esecuzione.

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)

Parametri

dataSource
Object

Origine dati per il DataGrid controllo.

dataMember
String

Stringa DataMember che specifica la tabella a cui eseguire l'associazione all'interno dell'oggetto restituito dalla DataSource proprietà .

Eccezioni

Uno o più argomenti non sono validi.

L'argomento dataSource è null.

Esempio

Nell'esempio di codice seguente vengono impostati rispettivamente e DataSourceDataMember su e DataTableDataSetin DataSet.

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

Commenti

Per reimpostare la DataSource proprietà, è necessario utilizzare il SetDataBinding metodo in fase di esecuzione.

Per altre informazioni sull'impostazione di un'origine dati valida, vedere la DataSource proprietà .

È possibile creare una griglia che consente agli utenti di modificare i dati, ma impedisce loro di aggiungere nuove righe usando come DataView origine dati e impostando la AllowNew proprietà su false. Quando è DataSource un DataView oggetto o DataTable, impostare su DataMember una stringa vuota ("").

Si applica a

Vedi anche