I have a list of Orders (parent list).
Each Order contains multiple products (child list).
(Order ... Product is 1...n relationship)
Here my classes:
public class Order { public Order() { } public int orderId { get; set; } public string customerName { get; set; } public string customerEmail { get; set; } public virtual ICollection<Item> items { get; set; } } public class Item { public Item() { } public string itemId { get; set; } public string itemName { get; set; } public int itemPrice { get; set; } public virtual Order order { get; set; } } public class CompanyContext : DbContext { public CompanyContext(): base() { } public DbSet<Order> Order { get; set; } public DbSet<Item> Item { get; set; } }
OnLoad I use dataRepeater to display all orders. For each datarepeater row, I manually load all the products in a richTextBox1,
which is placed inside of each datarepeater row:
protected override void OnLoad(EventArgs e) { Program.CompanyContext _context = new Program.CompanyContext(); List<list_inside_list.Program.Order> listOrders = _context.Order.ToList(); program_OrderBindingSource1.DataSource = listOrders; List<list_inside_list.Program.Item> listItems = _context.Item.ToList(); DataRepeaterItem currItem = new DataRepeaterItem(); for (int j = 0; j < this.dataRepeater1.ItemCount; j++) { this.dataRepeater1.CurrentItemIndex = j; var currentOrder = (list_inside_list.Program.Order)program_OrderBindingSource1.Current; foreach (var item in currentOrder.items) { dataRepeater1.CurrentItem.Controls["richTextBox1"].Text = dataRepeater1.CurrentItem.Controls["richTextBox1"].Text + item.itemName + "\n"; } } }Problem:
For a large quantity of data, and when having gone through the first datarepeater rows (scrolling or arrow-up or -down), richTextBox1 for each row starts to display incorrect data. It only shows some data of the richTextBoxes that were lastly shown.
My Troubleshooting:
1. Repopulating each richTextBox1 through CurrentItemIndexChanged does not solve the problem. It still displays data of the richTextBoxes that were lastly shown.
2. Even using CurrentItemIndexChanged without OnLoading (for example button1 click) and filling each richTextBox1, the first 5 or so richTextBox1 are correctly filled with data, but any later richTextBox1 again starts to show incorrect data (data of the first 5 or so richTextBox1).
3. When using CurrentItemIndexChanged and a new richTextBox2, which is placed outside of the datarepeater, correct data is shown.
Anyone knows how to help? My goal is to display the foreign key child list (in my case "Item.itemName") for every parent (in my case "Order") inside of each datarepeater row, prefereably OnLoad.
Best regards,
philipp-fx