Problems With BindingList<> part 2.

I have got closer to cleaning up the BindingList<> problem:

using System.Collections.Generic;
using System.ComponentModel;

namespace WindowsApplicationDataBinding
{
public class Node
{
private string _Name;
public string Name{ get{return _Name;} set{_Name = Name;}}

private int _Age;

public int Age
{
get { return _Age; }
set { _Age = value; }
}

public Node(string name, int age)
{
_Name = name;
_Age = age;
}

public string Birthday { get { return “Unknown”; } }

}

public class BindingClass : BindingList, ITypedList
{
private PropertyDescriptorCollection _Description = null;

#region ITypedList Members

public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
{
if (_Description == null)
{
_Description = TypeDescriptor.GetProperties(typeof(Node)).Sort(new string[] {“Name”, “Age”});
}
return _Description;
}

public string GetListName(PropertyDescriptor[] listAccessors)
{
return typeof(Node).Name;
}

#endregion
}
}

This version allows the application to specify the sort order of the columns.

The next step is to move this into an attribute based version.

It would also be useful if the description and hidden could be set on the same attribute.

What I want is to mark node as:

[BindingDetails(Description=”First Name”,Order=1,Hidden=False)]

string Name …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s