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
I'm not exactly sure I followed this but I do see that you have added two items to the ValueList which have the same value for the DisplayText property. This is not recommended because (a) it is confusing to the end user, since all they see is the DisplayText, which makes it impossible for them to differentiate between them, and (b) certain functions of the ValueList try to find items by matching the DisplayText, and this approach creates ambiguity.
I am also not sure I follow you.
At first, I declare two object CodeType:
ct.Add(new CodeType() { Id = 1, Name = "one" });ct.Add(new CodeType() { Id = 2, Name = "two" });
I then push them in my ValueList:
vl.ValueListItems.Add(ct[0], ct[0].Name); vl.ValueListItems.Add(ct[1], ct[1].Name);
I don't see where I have a duplicate for the DisplayText property...