Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
465
Issue with complex object binding.
posted

Hi,


I have a problem with the binding of a custom class with custom class object within it.


I have a class Code which contain a class CodeType:
public class Code
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public CodeType CodeTypeName { get; set; }
}
public class CodeType
{
    public int Id { get; set; }
    public string Name { get; set; }
}


When I try to load the form with the following code:
public partial class Form1 : Form
    {
        private Infragistics.Win.ValueList vl = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<CodeType> ct = new List<CodeType>();
            ct.Add(new CodeType() { Id = 1, Name = "one" });
            ct.Add(new CodeType() { Id = 2, Name = "two" });

            List<Code> c = new List<Code>();
            c.Add(new Code() { ID = 1, Name = "test", Description = "test", CodeTypeName = ct[0] });
            c.Add(new Code() { ID = 2, Name = "test", Description = "test", CodeTypeName = ct[1] });
            c.Add(new Code() { ID = 3, Name = "test", Description = "test", CodeTypeName = new CodeType() { Id = 1, Name = "one" } });
            c.Add(new Code() { ID = 4, Name = "test", Description = "test", CodeTypeName = new CodeType() { Id = 2, Name = "two" } });

            vl = new Infragistics.Win.ValueList();
            vl.ValueListItems.Add(ct[0], ct[0].Name);
            vl.ValueListItems.Add(ct[1], ct[1].Name);

            this.ultraGrid1.DataSource = c;
        }

        private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            e.Layout.Bands[0].Columns["CodeTypeName"].ValueList = this.vl;
            e.Layout.Bands[0].Columns["CodeTypeName"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
        }
    }


I get invalid entry in the last two rows because even though the properties are the same. I believe the object itself is different because of it signature. Is there a way to prevent that from happening?

Is there a way to prevent that from happening?

I do not wish to add a ToString() or Equals() method override in my CodeType class.

Thank you

Parents Reply Children
No Data