BindingSource.DataSource 속성

정의

커넥터가 바인딩된 데이터 소스를 가져오거나 설정합니다.

public:
 property System::Object ^ DataSource { System::Object ^ get(); void set(System::Object ^ value); };
public object DataSource { get; set; }
public object? DataSource { get; set; }
member this.DataSource : obj with get, set
Public Property DataSource As Object

속성 값

데이터 소스 역할을 하는 Object입니다. 기본값은 null입니다.

예제

다음 코드 예제에서는 고객의 목록을 할당 합니다 DataSourceBindingSource 구성 요소입니다. 이 코드 예제에 제공 된 큰 예제의의 일부인 방법: BindingSource ResetItem 메서드를 사용 하 여 변경 알림 발생합니다.

void Form1_Load( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   // Create and populate the list of DemoCustomer objects
   // which will supply data to the DataGridView.
   List< DemoCustomer^ >^ customerList = gcnew List< DemoCustomer^ >;
   customerList->Add( DemoCustomer::CreateNewCustomer() );
   customerList->Add( DemoCustomer::CreateNewCustomer() );
   customerList->Add( DemoCustomer::CreateNewCustomer() );
   
   // Bind the list to the BindingSource.
   this->customersBindingSource->DataSource = customerList;
   
   // Attach the BindingSource to the DataGridView.
   this->customersDataGridView->DataSource =
      this->customersBindingSource;
}
private void Form1_Load(System.Object sender, System.EventArgs e)
{
    // Create and populate the list of DemoCustomer objects
    // which will supply data to the DataGridView.
    List<DemoCustomer> customerList = new List<DemoCustomer>();
    customerList.Add(DemoCustomer.CreateNewCustomer());
    customerList.Add(DemoCustomer.CreateNewCustomer());
    customerList.Add(DemoCustomer.CreateNewCustomer());

    // Bind the list to the BindingSource.
    this.customersBindingSource.DataSource = customerList;

    // Attach the BindingSource to the DataGridView.
    this.customersDataGridView.DataSource = 
        this.customersBindingSource;
}
Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Me.Load
    ' Create and populate the list of DemoCustomer objects
    ' which will supply data to the DataGridView.
    Dim customerList As List(Of DemoCustomer) = _
    New List(Of DemoCustomer)
    customerList.Add(DemoCustomer.CreateNewCustomer())
    customerList.Add(DemoCustomer.CreateNewCustomer())
    customerList.Add(DemoCustomer.CreateNewCustomer())

    ' Bind the list to the BindingSource.
    Me.customersBindingSource.DataSource = customerList

    ' Attach the BindingSource to the DataGridView.
    Me.customersDataGridView.DataSource = Me.customersBindingSource
End Sub

설명

DataSource 다양 한 형식과 개체 유형 목록을 포함 하 여 데이터 원본 속성을 설정할 수 있습니다. 결과 데이터 소스 목록으로 노출 됩니다. 다음 표에서 일부 일반적인 데이터 원본 및 목록 계산 결과 보여 줍니다.

데이터 원본 속성 목록 결과
null IBindingList 개체입니다. 추가 된 항목의 형식으로 목록을 설정 항목을 추가 합니다.
null 사용 하 여 DataMember 설정 지원 되지 ArgumentException합니다.
목록이 아닌 형식 또는 "T" 형식의 개체 IBindingList "T" 형식입니다.
배열 인스턴스 IBindingList 배열 요소를 포함 합니다.
IEnumerable 인스턴스 IBindingList 포함 하는 IEnumerable 항목입니다.
"T" 형식을 포함 하는 인스턴스 목록 IBindingList "T" 형식은 포함 하는 인스턴스.

또한 DataSource 와 같은 다른 목록 형식으로 설정할 수 있습니다 IListSource 하 고 ITypedList 하며 BindingSource 적절 하 게 처리 됩니다. 이 경우 목록에 포함된 형식에는 매개 변수가 없는 생성자가 있어야 합니다.

제공 된 참조를 둘 이상 목록 또는 테이블을 포함 하는 경우 데이터 원본에 설정 하는 경우 설정 해야 합니다 DataMember 바인딩할 목록을 지정 하는 문자열 속성입니다. 이 속성이 발생 하는 설정 된 DataSourceChanged 이벤트입니다.

참고

변경한 경우를 DataSource 속성 값을 이렇게 해야 사용자 인터페이스 (UI) 스레드에서 UI 변경 내용을 반영 하는지 확인 합니다.

DataSource 속성은 기본 속성을 BindingSource 클래스입니다.

적용 대상

추가 정보