‫Welcome back.
‫In this video, we are going to add another list which will show us our associated animals list.
‫As you know, we have a list of zoos and then we have a list of animals.
‫And we need a list where we see the animals that are at a specific zoo.
‫And for example, if I click on New York, then I want to see in this additional list view, which we
‫have to set up the additional animals that are in New York.
‫So let's go ahead and just add that we need to go to our Zemo file first because we need to add another
‫list.
‫So I'm just going to enter those two or access those two elements, and I'm going to copy and paste
‫them so I can drag them to the side.
‫So now this one will not state list of the zoos, but it will be the associated animals list.
‫And so see.
‫A So not a c k associated animals list.
‫And now we have this one here which had the name list, zoo copies, and we want this to be list associated
‫animals.
‫So it just has a different name and then everything else is the same.
‫All right.
‫So now if we want to add functionality when something in here is clicked, we can of course do that
‫manually.
‫We can type it out or we can simply double click on it.
‫And you see it will create a selection change event for us.
‫So here a selection change event args are handled over and this is for list zoos.
‫So whenever we press on list zoos, this will be triggered.
‫And in order to check that, we can simply show that onto our console and list.
‫Zoos was clicked.
‫It's just going to be simple for now.
‫What we want to do is actually, well, update our other list once that is clicked.
‫Now let's check it out and I'm going to press on New York and you see lists, zoos was clicked, same
‫for Tokyo, list was clicked and so forth.
‫All right.
‫So of course, I don't want to show a message box here.
‫This was just for testing purposes so that you see what this selection changed does.
‫Now, what we need is another method which is very similar to the one that shows the zoos we need to
‫show the associated animals.
‫And well, actually what we can do is we can even copy that code here and just adjust it accordingly.
‫So we know we want to show animals.
‫So I'm going to show associated animals.
‫This is a new name of the method.
‫So I just copied and pasted the whole show Zoo's method.
‫And now I have this try and catch block again, which is trying to execute some query code and if it
‫didn't work, it's going to catch it and a message box will show up.
‫All right.
‫Now in here, I have a query, and that query is rather simple, simple right now.
‫And we need to make it a little more in-depth.
‫So instead of select star from Zoo, we need to go ahead and use select from animal a inner join zoo
‫animal that a on a dot ID is equal to z a dot animal ID animal ID.
‫So what we're pretty much saying is create those two or take those two tables, join them together,
‫and then check where the ID and of the animal and the zoo animal are the same and then go ahead and
‫display that to us.
‫So where the zoo ID is equal to at zoo ID and zoo ID is something that we will set up in a second.
‫So this adds where ID is like a variable.
‫You could say, okay, we are adding a variable in our query and now we can go ahead and set that variable
‫in code.
‫So I'm going to put that in a second line.
‫All right.
‫So now that we have that, what we next need to do is instead of setting up the SQL adapter, as we
‫did, we need an SQL Command because I use this at Zoo ID and in order to use it as a variable kind
‫of thing, I need to use an SQL Command.
‫And this is going to be called SQL Command, and that one is a new SQL Command, which will allow us
‫to use the query with the SQL Connection.
‫So from now it looks like it's an adapter, but we are going to add things to the command.
‫So we cannot simply add something like what zoo ID is to an SQL adapter, but we can add it to an SQL
‫command, which we then hand over to the SQL adapter.
‫So what we need to do is instead of running the query and the SQL connection here, we hand over the
‫SQL Command.
‫All right.
‫So we create a new SQL Command, which takes the query with the SQL Connection, and we hand that over
‫to SQL adapter.
‫And now we can go ahead and apply things to this SQL Command.
‫So this means that we can add a parameter to that.
‫So I'm going to do that with SQL Command DOT parameters.
‫There's a property called Parameters and it has a method called Add with value.
‫And then here I'm just going to say add zu id.
‫It's going to be my list.
‫Zoos that selected value.
‫All right.
‫And what what does that mean?
‫Well, zoo ID, as we know, is within our zoo animal.
‫Table.
‫So I'm going to show you that we have this zoo ID here, this one.
‫That's the ID of the zoo.
‫And that's the idea of the animal that is at that zoo.
‫And we want to have that.
‫So we are using it in our case class and we use that for this query here.
‫And now we want to hand over a specific ID, which is based on what we have selected in our list box.
‫So we have this list box here, the list where we have the different views.
‫And now when I click on one of them, I want the table to be updated.
‫And of course, it's not a zoo table.
‫It's an animal table here.
‫Animal table.
‫I'm going to copy that and I'm going to hand over this here now instead of the location.
‫I don't want to have the location of the animal.
‫I want to have the name of the animal.
‫And now, instead of applying it to the list zoos, which we applied earlier on when we showed all zoos,
‫we want to show the animals.
‫So we need to get the list, associated animals list.
‫And I'm just going to use it for all of the three lines.
‫All right.
‫And that is pretty much it.
‫So for you to understand what this ID is, I'm simply going to do the following.
‫I will show you lists.
‫Use dot selected value.
‫So this is a value and I will make a string out of it.
‫And now I want to show this in the message box.
‫So I'm going to create a new message box, dot show, and that will show me the value that was selected.
‫So you will see in a second what that means.
‫All right.
‫So there we are.
‫I click on, let's say, Tokyo, and you see the ID two comes up, I click on New York, the ID one
‫comes up.
‫Berlin.
‫Well, actually, Cairo ID was four.
‫So once I click on those, I want this method to be executed.
‫So show all associated animals.
‫And by the way, this is the ID that we hand over the zoo ID and by doing that we add this to this line
‫here to this query that we have here, and then it can execute that query and give us all the required
‫info on our list.
‫Associated Animals.
‫Now of course, as I said, instead of this message box, I would like to show this method here or execute
‫this method where we show associated animals.
‫So associated animals.
‫And now if we run that, let's run the code, let's click on New York and we see there are sharks and
‫clownfish.
‫Then in Tokyo are monkeys and wolves, Berlin Gecko, crocodile, Cairo Island Parrot and my milano
‫has all of them, so it has all the aid animals.
‫All right, so that's pretty much our associated animals list.
‫Great.
‫And now you know how to create your own associated lists.
‫We've done that before, but now you have seen the query.
‫Once again, we have set it up.
‫And you also have seen how we can use that in C-sharp by creating adapters, by using commands in order
‫to well adjust the queries based on execution or by based on code.
‫Because we couldn't add a fixed value here, we couldn't just say four because we want it to be a specific
‫value and that value is going to be our list.
‫Use selected value.
‫All right, great.
‫So I'd say that's good for this video.
‫And in the next video, we are going to add the list with all animals and some additional elements.
‫So see you there.