Hi,

I currently have two separate listboxes, one displaying a list of different leagues (With sponsors/prizes etc to do with leagues), & another listbox displaying a list of all the teams (So Team name, team nickname, team league etc..).

Both sets of data have been inputted via a Streamreader, I have created two classes, one for leagues, one for teams along with the getters & setters.

What i am trying to do is, when a League is clicked in the League listbox (Let's call this listbox1), the teams listbox (Listbox2) should produce the teams which are in that specific league.

As listbox2 contains a list of every team, from a range of leagues, I was wondering how you would filter the teams out so only the ones in that particular league will display in Listbox2.

My classes have different variable names for the league (Class League has League_Name, whereas Class Team has Team_League), if that is relevant at all..

Re-arrange your data structure slightly.

public class League
{
    public String Name {get;set;}
    public List<Team> Teams {get;set;}
    /* put other objects here relating to your prize and sponsors etc */
}

public class Team
{
    public String Name {get;set;}
    public List<Player> Players {get;set;}
    /* Other stuff relating to your team here */
}

Now when you add your list of Leagues to your list box, you can use the Name/Object you have stored to pull back a list of Teams that you can display in your second list box :)

Thank you for the reply, Although I am slightly unsure as to what List<Team> Teams does, & also where the 'Player' part comes from within the List<Player> Players.

Thank you :)

Basically you have a class Team which has a name and a List of Players. You might want a class for the players too, with name, awards, stats, etc..

Then you have a class League which has a name and a List of Teams. This can be declared as a List.

When the name is selected in the first listbox, iterate through the List of Teams for that league, and display each one in the second listbox.

In this manner the You don't need a property for League in the Team Class

Hi, would i be fine with just the List<Team> Teams as i do not need to go that in-depth with my details of the team? -> Clicking a specific league would just show all the team stats (Much like a league table on any sporting website)

I only went to that depth because it illustrates how you can traverse down classes to retrieve information.

that type of structure also simplifies your code.

Your way You have to search through your list of teams to establish the list of leagues, then when a league is clicked you have to search through the list again to find the teams belonging to that league.

This way everything is already sorted for you, load each name of league from the list, then when a league is clicked load that list of teams.

Additionally, if at some point you decide to expand this code or you have a similar type of project but much larger, you are already familiar with a more efficient approach and won't have to teach yourself what you should already know. If someone else will be looking at your code later, it will also make it much easier to read and figure out what the code is doing. You mentioned including stats, using this type of structure makes it quite easy to add a player class that would allow you to show things like to top players in different categories.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.