IListSource 接口

定义

向对象提供返回可以绑定到数据源列表的功能。

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.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public interface IListSource
派生
属性

示例

下面的代码示例演示如何实现 IListSource 接口。 名为 EmployeeListSource 的组件通过实现 GetList 方法公开了用于数据绑定的 IList。 有关完整代码列表,请参阅 如何:实现 IListSource 接口

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
    }
}

注解

通常使用此接口从不实现 IList 自身的对象返回可以绑定到数据源的列表。

绑定到数据可以在运行时或在设计器中发生,但每个绑定都有规则。 在运行时,可以绑定到以下任一项中的数据:

在设计器中,可以通过遵循相同的规则来初始化绑定到 Component 对象。

备注

IListSource 实现者可以返回一个 IList 包含 对象集合的 IList

属性

ContainsListCollection

获取一个值,该值指示集合是否是 IList 对象的集合。

方法

GetList()

从不实现 IList 本身的对象返回可以绑定到数据源的 IList

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

另请参阅