DataGrid.SetDataBinding(Object, String) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Define as DataSource propriedades e DataMember em tempo de execução.
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)
Parâmetros
- dataMember
- String
A DataMember cadeia que especifica a tabela a atribuir dentro do objeto devolvido pela DataSource propriedade.
Exceções
Um ou mais dos argumentos são inválidos.
O dataSource argumento é null.
Exemplos
O exemplo de código seguinte define o DataSource e DataMember como a DataSet, e a DataTable no DataSet, respetivamente.
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
Observações
Deve usar o SetDataBinding método em tempo de execução para reiniciar a DataSource propriedade.
Consulte a DataSource propriedade para mais detalhes sobre como definir uma fonte de dados válida.
Pode criar uma grelha que permita aos utilizadores editar dados, mas que os impeça de adicionar novas linhas, usando a DataView como fonte de dados e definindo a AllowNew propriedade para false. Quando o DataSource é a DataView ou DataTable, defina o DataMember para uma cadeia vazia ("").