Women in Technology

Hear us Roar

  Implementing Custom Data Bindable Classes: CollectionBase
Subject:   Implementing IComponent
Date:   2003-06-12 08:45:12
From:   jamesstill
Someone wrote to me and asked if it were possible to interact with this custom collection at design time. To do it you have to turn the class into a component. It's not as hard as it sounds really. You just have to implement IComponent in addition to CollectionBase:

public class Products : CollectionBase, IComponent {

IComponent requires you to write two things, a virtual method for Dispose() and an accessor for Site. Microsoft recommends that consumers of components explicitly call Dispose() rather than leaving them to the GC to cleanup. So put a public event in the Products class for the method to call:

public event EventHandler Disposed;


public virtual void Dispose() {
if (Disposed != null)
Disposed(this, EventArgs.Empty);

You'll also have to implement the Site property and return an ISite to the caller. I won't go into that here but you can find an example on MSDN at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcomponentmodelicomponentclasstopic.asp.

Full Threads Oldest First

Showing messages 1 through 3 of 3.

  • Implementing IComponent
    2006-02-08 23:33:06  Linxor [View]

    Implementing the IComponent interface is half of the work. You'll also need to add Visual Studio headers to your class.

    See the first page of the following tutorial to get the full scoop on creating a class that can be used for data binding inside the Visual Studio designer:

  • Implementing IComponent
    2004-04-28 08:19:05  wguerra [View]

    Hi, i have been looking for a way on making a collection class bindable at designtime, but i have not had luck.

    I already implement in my class IComponent, Site property, but it does not work, i don't what else i have to do in order to get this to work.

    If possible, could you write an article or give some link to help me accomplish this.

    I would really thank you
  • Implementing IComponent
    2003-12-18 11:36:56  anonymous2 [View]

    I bet you could use it as a base for a custom control, but you would just have to provide the designer for it, which to me is the most difficult part of developing a custom control.