ITypedList Arabirim
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ğlama için kullanılabilen özelliklerin bağlanacak nesnenin genel özelliklerinden farklı olduğu bağlanabilir bir listenin şemasını bulma işlevselliği sağlar.
public interface class ITypedList
public interface ITypedList
type ITypedList = interface
Public Interface ITypedList
- Türetilmiş
Örnekler
Aşağıdaki kod örneği, ITypedList arabiriminin nasıl uygulanduğunu gösterir. adlı SortableBindingList genel bir tür sınıfından BindingList<T> türetilir ve arabirimini ITypedList uygular. Tam kod listesi için bkz . Nasıl yapılır: ITypedList Arabirimini Uygulama.
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace ITypedListCS;
[Serializable()]
public class SortableBindingList<T> : BindingList<T>, ITypedList
{
[NonSerialized()]
readonly PropertyDescriptorCollection properties;
public SortableBindingList() : base()
{
// Get the 'shape' of the list.
// Only get the public properties marked with Browsable = true.
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(
typeof(T),
[new BrowsableAttribute(true)]);
// Sort the properties.
properties = pdc.Sort();
}
#region ITypedList Implementation
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
{
PropertyDescriptorCollection pdc;
if (listAccessors != null && listAccessors.Length > 0)
{
// Return child list shape.
pdc = ListBindingHelper.GetListItemProperties(listAccessors[0].PropertyType);
}
else
{
// Return properties in sort order.
pdc = properties;
}
return pdc;
}
// This method is only used in the design-time framework
// and by the obsolete DataGrid control.
public string GetListName(PropertyDescriptor[] listAccessors) => typeof(T).Name;
#endregion
}
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Windows.Forms
<Serializable()> _
Public Class SortableBindingList(Of Tkey)
Inherits BindingList(Of Tkey)
Implements ITypedList
<NonSerialized()> _
Private properties As PropertyDescriptorCollection
Public Sub New()
MyBase.New()
' Get the 'shape' of the list.
' Only get the public properties marked with Browsable = true.
Dim pdc As PropertyDescriptorCollection = TypeDescriptor.GetProperties(GetType(Tkey), New Attribute() {New BrowsableAttribute(True)})
' Sort the properties.
properties = pdc.Sort()
End Sub
#Region "ITypedList Implementation"
Public Function GetItemProperties(ByVal listAccessors() As System.ComponentModel.PropertyDescriptor) As System.ComponentModel.PropertyDescriptorCollection Implements System.ComponentModel.ITypedList.GetItemProperties
Dim pdc As PropertyDescriptorCollection
If (Not (listAccessors Is Nothing)) And (listAccessors.Length > 0) Then
' Return child list shape
pdc = ListBindingHelper.GetListItemProperties(listAccessors(0).PropertyType)
Else
' Return properties in sort order
pdc = properties
End If
Return pdc
End Function
' This method is only used in the design-time framework
' and by the obsolete DataGrid control.
Public Function GetListName( _
ByVal listAccessors() As PropertyDescriptor) As String _
Implements System.ComponentModel.ITypedList.GetListName
Return GetType(Tkey).Name
End Function
#End Region
End Class
Açıklamalar
Örneğin, bir tabloyu temsil customer eden bir DataView nesne kullanıyorsanız, öğesinin özelliklerini değil, temsil ettiği DataView nesnedeki özelliklere customerDataViewbağlamak istiyorsanız bu arabirimi kullanın.
Bu arabirim, bağlanabilir bir listenin tasarım zamanı desteği için gerekli değildir.
Verilere bağlama, çalışma zamanında veya tasarımcıda gerçekleşebilir, ancak her ikisi için de kurallar vardır. Çalışma zamanında, aşağıdakilerden herhangi birinde verilere bağlanabilirsiniz:
uygulayıcısının IListtürü kesin olarak belirlenmiş Item[] bir özelliğe sahip olması koşuluyla (yani, dışında Objectbir şey) öğesinin Type uygulayıcısı. Bunu, varsayılan özel uygulamasını Item[] yaparak gerçekleştirebilirsiniz. Kesin olarak belirlenmiş bir IList koleksiyonun kurallarına uygun bir koleksiyon oluşturmak istiyorsanız, türünden CollectionBasetüretmelisiniz.
uygulayıcısı ITypedList.
Tasarımcıda, aynı kuralları izleyerek nesnelere Component bağlamayı başlatabilirsiniz.
Veri kaynağına bağlama hakkında daha fazla bilgi için sınıfına System.Windows.Forms.Binding bakın.
Yöntemler
| Name | Description |
|---|---|
| GetItemProperties(PropertyDescriptor[]) |
PropertyDescriptorCollection Verileri bağlamak için kullanılan her öğedeki özellikleri temsil eden öğesini döndürür. |
| GetListName(PropertyDescriptor[]) |
Listenin adını döndürür. |
Şunlara uygulanır
Ayrıca bkz.
- BindingList<T>
- Nasıl yapılır: ITypedList Arabirimini Uygulama
- Windows Forms Veri Bağlama