BindingSource.DataSource Özellik

Tanım

Bağlayıcının bağlandığını veri kaynağını alır veya ayarlar.

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

Özellik Değeri

Veri Object kaynağı işlevi gören bir. Varsayılan değer: null.

Örnekler

Aşağıdaki kod örneği, bir bileşene DataSourceBindingSource müşteri listesi atar. Bu kod örneği, Nasıl yapılır: BindingSource ResetItem Yöntemini Kullanarak Değişiklik Bildirimleri Oluşturma başlığı altında sağlanan daha büyük bir örneğin parçasıdır.

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

Açıklamalar

DataSource özelliği türler, nesneler ve tür listeleri dahil olmak üzere bir dizi veri kaynağına ayarlanabilir. Sonuçta elde edilen veri kaynağı bir liste olarak gösterilir. Aşağıdaki tabloda yaygın veri kaynaklarından bazıları ve sonuçta elde edilen liste değerlendirmesi gösterilmektedir.

DataSource özelliği Sonuçları listeleme
null Nesnelerden oluşan boş IBindingList . Öğe eklemek, listeyi eklenen öğenin türüne ayarlar.
nullset ile DataMember Desteklenmez, yükseltir ArgumentException.
Liste dışı tür veya "T" türündeki nesne "T" türünde boş IBindingList .
Dizi örneği IBindingList dizi öğelerini içerir.
IEnumerable Örnek IBindingList Öğeleri içeren IEnumerable bir.
"T" türünü içeren liste örneği IBindingList "T" türünü içeren örnek.

Ayrıca, DataSource ve ITypedList gibi IListSource diğer liste türlerine ayarlanabilir ve BindingSource bunları uygun şekilde işler. Bu durumda, listede yer alan türün parametresiz bir oluşturucuya sahip olması gerekir.

Veri kaynağını ayarlarken, sağlanan başvuru birden fazla liste veya tablo içeriyorsa, özelliğini bağlanacak listeyi belirten bir dize olarak ayarlamanız DataMember gerekir. Bu özelliğin ayarlanması olayı tetikler DataSourceChanged .

Not

Özellik değerinde herhangi bir değişiklik DataSource yaparsanız, kullanıcı arabiriminin değişiklikleri yansıtmasını sağlamak için bunu kullanıcı arabirimi (UI) iş parçacığında yapmalısınız.

DataSource özelliği, sınıfı için varsayılan özelliktirBindingSource.

Şunlara uygulanır

Ayrıca bkz.