I'm trying to get data from two lists/sources to populate my datagrid view. I manage to print all fields for an animal but the list of Toys. How can I proceed with this one? What's the correct route?
This is what my code looks like:
What the code looks like to get the animals
And the class and properties from which fields are retrieved from:
Fields from source that shows up:
This is what my code looks like:
C#:
Petowner.Pets.Add(new Cat
{
Name = "Kissise",
Age = 3,
FavFood = "Whiskas",
Breed = "Ragdoll",
IsHungry = true,
// How can this list be printed as well?
Toys =
new List<Toy> {
new Bone {Size ="Large", Quality = 1},
}
});
What the code looks like to get the animals
C#:
dataGridView1.DataSource = Petowner.Pets;
And the class and properties from which fields are retrieved from:
C#:
abstract class Animal
{
// Properties
public string Name { get; set; }
public virtual int Age { get; set; }
public string FavFood { get; set; }
public string AnimalType
public string FavFood { get; set; }
public string Breed { get; set; }
public bool IsHungry { get; set; }
public List<Toy> Toys { get; set; } = new List<Toy>(); // How can this be added as well?
}
Fields from source that shows up:
Last edited: