23
avril
2007
IEnumerable et DataBinding
avril
2007
Quand une classe implémente l’interface IEnumerable, impossible de se binder à ses propriétés.
Le code suivant provoque donc une erreur au chargement de la Form :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.DataBindings.Add("Text", new Test(), "Toto");
}
}
public class Test : IEnumerable<string>
{
private string _toto;
public string Toto
{
get { return _toto; }
set { _toto = value; }
}
#region IEnumerable<string> Members
[...]
#endregion
}
{
public Form1()
{
InitializeComponent();
textBox1.DataBindings.Add("Text", new Test(), "Toto");
}
}
public class Test : IEnumerable<string>
{
private string _toto;
public string Toto
{
get { return _toto; }
set { _toto = value; }
}
#region IEnumerable<string> Members
[...]
#endregion
}