IListSource 接口
定义
向对象提供返回可以绑定到数据源列表的功能。Provides functionality to an object to return a list that can be bound to a data source.
public interface class IListSource
public interface IListSource
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public interface IListSource
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public interface IListSource
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public interface IListSource
type IListSource = interface
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type IListSource = interface
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type IListSource = interface
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type IListSource = interface
Public Interface IListSource
- 派生
- 属性
示例
下面的代码示例演示如何实现 IListSource 接口。The following code example demonstrates how to implement the IListSource interface. 名为的组件 EmployeeListSource
IList 通过实现方法公开数据绑定的 GetList 。A component named EmployeeListSource
exposes an IList for data binding by implementing the GetList method. 有关完整的代码清单,请参阅 如何:实现 IListSource 接口。For a full code listing, see How to: Implement the IListSource Interface.
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
namespace IListSourceCS
{
public class EmployeeListSource : Component, IListSource
{
public EmployeeListSource() {}
public EmployeeListSource(IContainer container)
{
container.Add(this);
}
#region IListSource Members
bool IListSource.ContainsListCollection
{
get { return false; }
}
System.Collections.IList IListSource.GetList()
{
BindingList<Employee> ble = new BindingList<Employee>();
if (!this.DesignMode)
{
ble.Add(new Employee("Aaberg, Jesper", 26000000));
ble.Add(new Employee("Cajhen, Janko", 19600000));
ble.Add(new Employee("Furse, Kari", 19000000));
ble.Add(new Employee("Langhorn, Carl", 16000000));
ble.Add(new Employee("Todorov, Teodor", 15700000));
ble.Add(new Employee("Verebélyi, Ágnes", 15700000));
}
return ble;
}
#endregion
}
}
Imports System.ComponentModel
Public Class EmployeeListSource
Inherits Component
Implements IListSource
<System.Diagnostics.DebuggerNonUserCode()> _
Public Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub
<System.Diagnostics.DebuggerNonUserCode()> _
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
End Sub
'Component overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
#Region "IListSource Members"
Public ReadOnly Property ContainsListCollection() As Boolean Implements System.ComponentModel.IListSource.ContainsListCollection
Get
Return False
End Get
End Property
Public Function GetList() As System.Collections.IList Implements System.ComponentModel.IListSource.GetList
Dim ble As New BindingList(Of Employee)
If Not Me.DesignMode Then
ble.Add(New Employee("Aaberg, Jesper", 26000000))
ble.Add(New Employee("Cajhen, Janko", 19600000))
ble.Add(New Employee("Furse, Kari", 19000000))
ble.Add(New Employee("Langhorn, Carl", 16000000))
ble.Add(New Employee("Todorov, Teodor", 15700000))
ble.Add(New Employee("Verebélyi, Ágnes", 15700000))
End If
Return ble
End Function
#End Region
End Class
注解
通常,使用此接口可以从未实现自身的对象中返回可以绑定到数据源的列表 IList 。You typically use this interface to return a list that can be bound to a data source, from an object that does not implement IList itself.
绑定到数据时,可以在运行时或设计器中进行,但每个都有规则。Binding to data can occur at either run time or in a designer, but there are rules for each. 在运行时,可以通过以下任一操作绑定到数据:At run time, you can bind to data in any of the following:
的实施者 IList ,前提是实施者有一个强类型的 Item[] 属性 (也就是说,它 Type 是但 Object) 的。Implementer of IList, provided the implementer has a strongly typed Item[] property (that is, the Type is anything but Object). 您可以通过将默认实现设为私有来实现此目的 Item[] 。You can accomplish this by making the default implementation of Item[] private. 如果要创建 IList 遵循强类型集合的规则的,则应派生自 CollectionBase 。If you want to create an IList that follows the rules of a strongly typed collection, you should derive from CollectionBase.
的实施者 ITypedList 。Implementer of ITypedList.
在设计器中,可以 Component 遵循相同的规则来初始化到对象的绑定。In a designer, you can initialize binding to Component objects by following the same rules.
备注
的实现 IListSource 程序可以返回 IList 包含对象集合的 IList 。Implementers of IListSource can return an IList that contains a collection of IList objects.
属性
ContainsListCollection |
获取一个值,该值指示集合是否是 IList 对象的集合。Gets a value indicating whether the collection is a collection of IList objects. |
方法
GetList() |
从不实现 IList 本身的对象返回可以绑定到数据源的 IList。Returns an IList that can be bound to a data source from an object that does not implement an IList itself. |