BindingSource.DataSource 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
커넥터가 바인딩하는 데이터 원본을 가져오거나 설정합니다.
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 형식, 개체 및 형식 목록을 비롯한 여러 데이터 원본으로 설정할 수 있습니다. 결과 데이터 원본은 목록으로 노출됩니다. 다음 표에서는 몇 가지 공통 데이터 원본 및 결과 목록 평가를 보여 줍니다.
| DataSource 속성 | 결과 나열 |
|---|---|
null |
개체가 비어 IBindingList 있습니다. 항목을 추가하면 목록이 추가된 항목의 형식으로 설정됩니다. |
null with DataMember set |
지원되지 않음, 발생합니다.ArgumentException |
| "T" 형식의 목록이 아닌 형식 또는 개체 | "T" 형식이 비어 IBindingList 있습니다. |
| 배열 인스턴스 | IBindingList 배열 요소를 포함합니다. |
| IEnumerable 인스턴스 | IBindingList 항목을 포함하는 항목입니다IEnumerable. |
| "T" 형식을 포함하는 목록 인스턴스 | IBindingList "T" 형식을 포함하는 인스턴스입니다. |
또한 DataSource 같은 다른 목록 형식 IListSource 으로 설정할 수 있으며 ITypedListBindingSource 적절하게 처리합니다. 이 경우 목록에 포함된 형식에는 매개 변수가 없는 생성자가 있어야 합니다.
데이터 원본을 설정할 때 제공된 참조에 둘 이상의 목록 또는 테이블이 포함된 경우 바인딩할 목록을 지정하는 문자열로 속성을 설정 DataMember 해야 합니다. 이 속성을 설정하면 이벤트가 발생합니다 DataSourceChanged .
메모
속성 값을 변경하는 DataSource 경우 UI(사용자 인터페이스) 스레드에서 변경 내용을 반영하도록 해야 합니다.
이 DataSource 속성은 클래스의 기본 속성입니다 BindingSource .