DataGrid.SetDataBinding(Object, String) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
DataSource Mengatur properti dan DataMember pada waktu proses.
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)
Parameter
- dataMember
- String
String DataMember yang menentukan tabel yang akan diikat ke dalam objek yang dikembalikan oleh DataSource properti .
Pengecualian
Satu atau beberapa argumen tidak valid.
Argumennya dataSource adalah null.
Contoh
Contoh kode berikut mengatur DataSource dan DataMember ke DataSet, dan DataTable di DataSet, masing-masing.
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
Keterangan
Anda harus menggunakan metode pada SetDataBinding waktu proses untuk mengatur ulang DataSource properti.
DataSource Lihat properti untuk detail selengkapnya tentang mengatur sumber data yang valid.
Anda dapat membuat kisi yang memungkinkan pengguna mengedit data tetapi mencegah mereka menambahkan baris baru dengan menggunakan DataView sebagai sumber data dan mengatur AllowNew properti ke false.
DataSource Ketika adalah DataView atau DataTable, atur DataMember ke string kosong ("").