Edit

Share via


IListSource Interface

Definition

Provides functionality to an object to return a list that can be bound to a data source.

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
Derived
Attributes

Examples

The following code example demonstrates how to implement the IListSource interface. A component named EmployeeListSource exposes an IList for data binding by implementing the GetList method. 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
    }
}

Remarks

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:

  • Array

  • Implementer of IList, provided the implementer has a strongly typed Item[] property (that is, the Type is anything but Object). You can accomplish this by making the default implementation of Item[] private. If you want to create an IList that follows the rules of a strongly typed collection, you should derive from CollectionBase.

  • Implementer of ITypedList.

In a designer, you can initialize binding to Component objects by following the same rules.

Note

Implementers of IListSource can return an IList that contains a collection of IList objects.

Properties

ContainsListCollection

Gets a value indicating whether the collection is a collection of IList objects.

Methods

GetList()

Returns an IList that can be bound to a data source from an object that does not implement an IList itself.

Applies to

Product Versions
.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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also