Hello group!
I've created a collection class that implements ITypedList:
class MyCollection : IBindingList, IList, ICollection, IEnumerable, ITypedList
{
PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
{
PropertyDescriptorCollection props = new PropertyDescriptorCollection(null);
// Here I add items of type MyPropertyDescriptor to the props collection
props.Add(new MyPropertyDescriptor("Property1"));
props.Add(new MyPropertyDescriptor("Property2"));
props.Add(new MyPropertyDescriptor("PropertyN"));
return props;
}
}
class MyPropertyDescriptor : PropertyDescriptor
{
public MyPropertyDescriptor(string propertyName) : base(propertyName, null)
{
}
// Here I override some methods and properties.
public override string DisplayName
{
get
{
string displayName = string.Empty;
switch(this.Name)
{
case "Property1":
displayName = "My Custom Text 1";
break;
case "Property2":
displayName = "My Custom Text 2";
break;
case "PropertyN":
displayName = "My Custom Text N";
break;
}
return displayName;
}
}
public object GetValue(object component)
{
return component.GetType().GetProperty(this.Name).GetValu e(component, null);
}
public void SetValue(object component, object value)
{
component.GetType().GetProperty(this.Name).SetValu e(component, value, null);
}
}
Everything works fine, all the overriden methods are invoked well, except for the overriden property DisplayName, if I set a break point inside the property, the debuger never stops there.
When I bind my collection to a DataGrid control, the columns are shown in the perfect order (1, 2, N), but they have the property name instead of my custom text.
I'd really appreaciate any help...
Thank you all...