MindScape

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

有时候我们希望能自己写一个component,并可以像DataSet、那样可以在设计时可以显示出其中的collection, 以及collection中的可绑定的属性。一下提供了一个简要的介绍:

IListSource,如果你的component本身不是一个Collection(本身不实现IList 或IBindingList)的话,你可以用这个接口返回一个实现该collection的IList .一个典型的例子就是DataSet。
ITypedList, 该接口用于返回需要显示在binding list picker中的属性。

一个简单的例子(摘自一个component,它实现了ITypedList, IBindingList).

#region ITypedList Members

 

public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)

{

     MessageBox.Show("sdfasf");

     // TODO:  Add UserControl1.GetItemProperties implementation

     PropertyDescriptorCollection col = TypeDescriptor.GetProperties(this);

     PropertyDescriptorCollection colnew = new PropertyDescriptorCollection(null);

     MyBindableAttribute myAttr = new MyBindableAttribute();

     foreach(PropertyDescriptor prop in col)

     {

         if (prop.Attributes.Contains(myAttr))

              colnew.Add(prop);

     }

     return colnew;

 

}

 

public string GetListName(PropertyDescriptor[] listAccessors)

{

     MessageBox.Show("GetListName");

     // TODO:  Add UserControl1.GetListName implementation

     foreach(PropertyDescriptor prop in listAccessors)

         MessageBox.Show(prop.DisplayName);

     MessageBox.Show("GetListName");

 

     return "Hello";

}

 

#endregion

 

class MyBindableAttribute : Attribute {}

 

 

[MyBindable]

public string Text

{

     get  {return string.Empty;}

}

 

posted on 2004-02-03 23:35  Jonny Yu  阅读(1771)  评论(1编辑  收藏  举报