다음을 통해 공유


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설정합니다 DataSourceDataMemberDataSet.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

설명

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

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

사용자가 데이터를 편집할 수 있지만 데이터 원본으로 사용하고 속성을 />로 설정하여 새 행을 추가하지 못하게 하는 그리드를 만들 수 있습니다. DataSource a DataView 또는 DataTable인 경우 빈 문자열("")로 설정합니다DataMember.

적용 대상

추가 정보