BindingSource.DataSource Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
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 bir müşteri listesi atar. Bu kod örneği, How to: Raise Change Notifications Using the BindingSource ResetItem Method (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 de dahil olmak üzere bir dizi veri kaynağına ayarlanabilir. Sonuçta elde edilen veri kaynağı liste olarak gösterilir. Aşağıdaki tabloda bazı yaygın veri kaynakları ve sonuçta elde edilen liste değerlendirmesi gösterilmektedir.
| DataSource özelliği | Sonuçları listeleme |
|---|---|
null |
Nesnelerden oluşan bir boş IBindingList . Öğe ekleme, 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çeren. |
| IEnumerable Örnek | IBindingList Öğeleri içeren IEnumerable bir. |
| "T" türü içeren liste örneği | IBindingList "T" türünü içeren örnek. |
Buna ek olarak, DataSource ve gibi IListSourceITypedList 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 .
Uyarı
Ö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 yapmanız gerekir.
DataSource özelliği, sınıfı için varsayılan özelliktirBindingSource.