DataGrid.SetDataBinding(Object, String) 메서드

정의

런타임에 DataSourceDataMember 속성을 설정합니다.

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)

매개 변수

dataSource
Object

DataGrid 컨트롤에 대한 데이터 소스입니다.

dataMember
String

DataMember 속성에서 반환하는 개체 내에서 바인딩할 테이블을 지정하는 DataSource 문자열입니다.

예외

하나 이상의 인수가 잘못되었습니다.

dataSource 인수가 null인 경우

예제

다음 코드 예제에서는 각각 , 및 in을 DataSet설정합니다 DataSource DataMember DataSet.DataTable

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

설명

속성을 다시 설정하려면 런타임에 메서드를 DataSource 사용해야 SetDataBinding 합니다.

유효한 데이터 원본 설정 DataSource 에 대한 자세한 내용은 속성을 참조하세요.

You can create a grid that enables users to edit data but prevents them from adding new rows by using a DataView as the data source and setting the AllowNew property to false. DataSource a DataView 또는 DataTable이면 빈 문자열("")로 설정합니다DataMember.

적용 대상

추가 정보