The issue I'm noticing is this line of code:
tempList.Add(orderables);
In this full code:
AssociatedComboItems ai = new AssociatedComboItems();
List<Orderables> tempList = new List<Orderables>();
Orderables orderables = new Orderables();
foreach (var t in comboBox1.Items)
{
ai.ComboBoxItem = t.ToString();
for (int i = 0; i < fpSpread1.ActiveSheet.RowCount; i++)
{
orderables.Display = fpSpread1.ActiveSheet.Cells[i, 1].Text;
orderables.ShowInDSR = (bool)fpSpread1.ActiveSheet.Cells[i, 0].Value;
orderables.DisplayOrder = i;
tempList.Add(orderables);
}
ai.AssociatedItems = tempList;
tempList.Clear();
if(AssociatedItems == null)
AssociatedItems = new List<AssociatedComboItems>();
AssociatedItems.Add(ai);
}
When I put my breakpoint on the line mentioned above (tempList.Add(orderables);
), the first time it adds the item correctly to the templist
and it will have one item in it. The second time it will add the correct item to the list but if I hover over tempList
and want to see its contents, although it has two items, both of them are the same - they are both now the second item that was added to the list. It has overwritten the first one.
I can't figure out what is going wrong with this and why it is happening.