DataGrid.SetDataBinding(Object, String) Metodo

Definizione

Imposta le proprietà DataSource 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 controllo DataGrid.

dataMember
String

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

Eccezioni

Uno o più argomenti non sono validi.

Il valore dell'argomento dataSource è null.

Esempio

Nell'esempio di codice seguente vengono impostati rispettivamente e DataSource su e DataSetin DataTable DataSet.DataMember

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 altri dettagli 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. DataSource Quando è un DataView oggetto o DataTable, impostare su DataMember una stringa vuota ("").

Si applica a

Vedi anche