I have a method that fills a ListBox
with objects (custom class)
internal void UpdateList() {
foreach (Item item in Container.Items)
List.Items.Add(item);
}
Container
also is a custom class that holds a List<Item>
where all objects of this container is stored.
Now, the user can select (using a ComboBox
) to display a certain Container
and I want to select all the Item
s that this container stores.
I tried it by
private void ContainerList_SelectedIndexChanged(Object sender, EventArgs e) {
Container container = (Container)ContainerList.SelectedItem;
foreach (Item item in container.Items)
List.SelectedIndecies.Add(List.Items.IndexOf(item));
}
But this didn't do the trick: Nothing is selected. I feel the problem is that though the objects in Container.Items
and List.Items
have the same fields, the are not the same for the program.
I hope you understand my problem - How can I get this working?
Edit
To clarify; I want the containers to be editable. So, the user selects a Container from the List and only the Items that are in this container are selected in the ListBox.
The ones not in the Container have still to be in the ListBox, just not selected
So, the user can edit the Items of the container!