Merge Multi Colums in Binding
public class MergeMultiColumsBinding : Binding
{
public string[] Properties;
public MergeBinding( string property , object ds , string member , params string[] prop )
: base( property , ds , member )
{
this.Properties = prop;
}
protected override void OnFormat( ConvertEventArgs e )
{
CurrencyManager cm = this.Control.BindingContext[this.DataSource] as CurrencyManager;
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties( cm.Current );
StringBuilder sb = new StringBuilder();
for( int i = 0 ; i < Properties.Length - 1 ; i++ )
{
sb.AppendFormat( "{0} ," , pdc[Properties[i]].GetValue( cm.Current ) );
}
sb.AppendFormat( "{0}" , pdc[Properties[Properties.Length - 1]].GetValue( cm.Current ) );
e.Value = sb.ToString();
}
protected override void OnParse( ConvertEventArgs e )
{
string[] values = e.Value.ToString().Split( ',' );
CurrencyManager cm = this.Control.BindingContext[this.DataSource] as CurrencyManager;
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties( cm.Current );
for( int i = 0 ; i < Properties.Length ; i++ )
{
pdc[Properties[i]].SetValue( cm.Current , values[i] );
}
}
}