ā Combobox writes out collection instead of the values
Hi im working in a WPF application for a university project thats based on Harry Potter. So i have built Hogwarts, and then put in the different houses, Gryffendor and so and so in different classes and built them after a house class to follow the same criteria. So the story is that you supposed to put in a password, and then fill in in a combobox which house the password is for. But when I do the combobox like bellow it just says collection, and not the differnt houses, why? Also added more code into here: https://paste.mod.gg/
BlazeBin
A tool for sharing your source code with the world!
27 Replies
You need to save the code and copy+paste the link
rn the link is just to the base website, not your code
BlazeBin - uakbccbribmb
A tool for sharing your source code with the world!
The combobox won't know by default what data you want it to display from the items you've added. Somewhere you need a line like:
cboHouses.DisplayMemberPath = "NameOfPropertyToDisplay";
something like this?
Well it seems that
hogwarts.Griffendor
is a collection and cboHouses.Items.Add(hogwarts.Griffendor)
adds a collection to the combobox items. You put fire in the hole and wondering why there is fire in the hole ;o)
I would say your class design is a little messAh sorry yeah I hadn't spotted that
no stress, but should that be in the hogwarts or somewhere else?
what Sir Rufo is pointing out is that you're not adding individual objects to your combobox, you're adding 4 lists to it (though they all only contain 1 item each), and that really they probably shouldn't be in lists
okeyy
i.e. here:
Why would you need a list for each house when there will only ever be one each of them
okej, so maybe i just do like a normal construktor and in parameter?
you just need to make them not lists really
or have a list of Houses:
but then i cant use the add method to add them to hogwarts
in option 1 you wouldn't need to, in option 2 you could
Add
them to Hogwarts.Houses
Do you have to use the add method or something?no not really, but then how do i put in all the values from lets say griffendor?
ohh i see, maybe like this?
the problem now is that even though i added this: the name of the solution still comes up
Do you have to have a separate type for each house?
yes
but sorted it out now, just needed it to be put in the class for the houses.
thanks everybody!
it would probably make more sense to just have the House class and have a Name property in it, rather than separate classes for each house
Yeah, that's what I was thinking
i know but the assigment says to have different classes for each house š¦
Could you post that assignment? It sounds very strange even for an exercise
The assigment is not in English so don`t know even if I post it that it would be understandable
but talked to my professor about it and they say that we need to practice OOP and hence why they want us to create many different classes and so!
They definitely didn't mean a different instance of a class for each House?
That was also on my mind š
I guess I would do something like
š
Now we have a class for each house
And a big practice of OOP => Inheritance
oh you would put that in the same class as the house?
You put everything in the parent class which is common for all child classes, yes