DataGrid.SetDataBinding(Object, String) 메서드

정의

런타임에 DataSourceDataMember 속성을 설정합니다.Sets the DataSource and DataMember properties at run time.

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 컨트롤에 대한 데이터 소스입니다.The data source for the DataGrid control.

dataMember
String

DataMember 속성에서 반환하는 개체 내에서 바인딩할 테이블을 지정하는 DataSource 문자열입니다.The DataMember string that specifies the table to bind to within the object returned by the DataSource property.

예외

하나 이상의 인수가 잘못되었습니다.One or more of the arguments are invalid.

dataSource 인수가 null인 경우The dataSource argument is null.

예제

다음 코드 예제에서는 및를 DataSource DataMember 각각의 및로 설정 합니다 DataSet DataTable DataSet .The following code example sets the DataSource and DataMember to a DataSet, and a DataTable in the DataSet, respectively.

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 .You must use the SetDataBinding method at run time to reset the DataSource property.

DataSource유효한 데이터 원본 설정에 대 한 자세한 내용은 속성을 참조 하세요.See the DataSource property for more details about setting a valid data source.

사용자가 데이터를 편집할 수 있지만를 DataView 데이터 원본으로 사용 하 고 속성을로 설정 하 여 새 행을 추가 하는 것을 방지 하는 그리드를 만들 수 있습니다 AllowNew false .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이 또는 인 경우 DataViewDataTable DataMember 빈 문자열 ("")로 설정 합니다.When the DataSource is a DataView or DataTable, set the DataMember to an empty string ("").

적용 대상

추가 정보