✅ List doesnt show multiple inputs
Hi i have this code, and when looping throught all the houses and the second member of each house is put in you can only see one member still in the list, why?
16 Replies
so in the list its supposed to be 2 "students" but only one can be seen in the list??
currentHouse.SortingHat(newWizard, currentHouse);
seems to be where you're adding the new wizard to a house
yet that code was not included in your paste
so how are we supposed to be able to help?oh im sorry completely forgot!
thats the same code you just pasted :p
also, you have some very confusing code here
seems convoluted, why not just make it
sorry here is he hat!
uh..
wait
thats a method ON A HOUSE
that takes a house as a parameter
now that is both silly and confusing
currentHouse.SortingHat(newWizard, currentHouse);
note how currentHouse
is specified twice here
and the name is also confusing, that method only does one thing: register a wizard as a member of a housei know but i have to use the name thats specified in the assigment.
okay leave the name, but fix the rest of the issues
I semi-rewrote this program as a console app, looks a bit like this
oh we not allowed to co console thoug
so i have that they get added and says that they member two and so, but they just dont pop up in my list box.
you have 4 list boxes as far as I can tell
yes
so i can add the first time and everything works fine, but then when i try to add the second member to the list it doesnt work..
its just adding more elements to the listbox it looks like it overrites its self
Ah, I see why
you "update" the list by assigning its itemsource
but if the itemsource is the same as it previously was, there is no reason to re-render even when the itemsource is assigned again
and thats exactly whats happening here
you'll need to call
.Refresh()
on your updated listviewoh i have never seen refresh before but will give it a go!
where and how im a supposed t refresh?
i have got it now! just put the itemssource to null first
thank you for all the input!
You don’t need to keep setting the ItemsSource each time you add a new wizard to your members list. Simply set it once when initialise the window / components. Secondly if you use an ObservableCollection<T> instead of a List<T>, you will get built in INotifyPropertyChange which means you’ll get two way data binding and the list view will “automatically” update when you add a member to that ObservableCollection. If you don’t use an ObservableCollection, you would need to implement INotifyPropertyChanged