Question Problem understanding Classes and lists.

Status
Not open for further replies.

Morry

Member
Joined
Feb 21, 2017
Messages
10
Programming Experience
Beginner
Hi everyone!

I have been using Lists in classes as property but gott in a bit of a closed road now. I wanted to create a program where i have a list of people and the movies they like so..

<unreadable code removed>

Now with the code above i tryed to create a collection where i have multipale movies under one user, and i did it so that if i select a user from the Users list i can klick the button and it would move all the movies from the movie list to that user in the users list.

The problem is iam unable to retain the list of movies to display them in another list, i tryed many things but it didn't work. so now when klick i get the last saved values and i can't really specify anything from the list like a different use with his own movies etc..

So please can anyone tell me what i should use, or even search for in the internet because i don't seem to be able to search for the correct terms or the right things, And couple more questions :joyous:.

1. if i use Combobox to display the users, do they still have the movies attached to them?
2. how can i movie items from a Listbox to a List but one item at the time, i already tried IF, Foreach and they didn't work.

Thank you for your help!
 
So, that is my current code, i posted the form and classes, i used the example of the movies because i had to change all the names to english which i did at the end to be able to post here, but the concept is the same.

I want to create a program where i have two lists, one for teams and the other for players, then i want to be able to save those players to one team, so that when i create a match i can then get all the players from that team into a listbox.

so the set up would look like this
Capture.PNG


In the left you have the Team and players listboxes, to the right you have the Match listbox and the four listboxes which i want to use to move players between those listboxes, so for example ListboxHometeam will have 25 players then i can only move 11 of them to the listbox beside it Hometeam2.

Iam having many problems with this build.

1. I don't know how to make the program show me the players in a specific team when i choose that team in one of the Comboboxes(either the Home Team or the Foreignteam).

2. I can't move only one item between different lists or a list and a listbox because iam using Datasource but i tryed other ways and they just made it even harder or just messed up the whole program.

3. I want to add a save option to save the matches, so that when i close the program everything is saved to a file so when i open it again i can see the matches and thus able to restart the matches with players etc..I think i know how to save to file but i just wanted to add this as en extra detail.


I hope i gave you enough info this time so i might get some idea or feedback from you!

Thank you!
 
We're not going to solve all the problems of the world in this one thread. Please FOCUS. Please keep each thread to a single topic and each topic to a single thread. In this thread, ask for help on a single, specific issue and post only the code that is relevant to that issue, and please don't include wads of empty space in your code because that just makes it harder to read.
 
@jmcilhinney
You should scroll up and see why i posted what you call "problems of the world", So far got nothing from the dame forums, they asked me to post my code and what my problems are and describe exactly what i want with the dame program, but you know what just F it...


Btw you really need to work on your attitude dude, people don't come here to beg for help and the this forum isn't the best or the only, so be a bit friendly with Newbies like me who just want to learn how to ###### program.
Let's take a step back and analyze what all is going on with your code, first off you post about adding movies to a person's collection but all of the code you post has to do with sports teams and having players on it which is basically the same thing as a person having movies but it's a confusing thing to switch context like that.
But back to the code, I see where you're creating new "teams" and adding it to the teams collection, but I'm not seeing anywhere where you're adding a player to a team, you are however creating a player and adding it to the Players collection, but there's no team assignment in your code. This is all very confusing for us to try to step back and figure out what's really going on with your code, which might be why jmc is getting a little snippy.

So, what I would do is step back and without even considering the Form (where all the ListBoxes and stuff is) but think about the classes and how each would relate to the others. I'll begin with the teams and players for ya, you'll probably want two classes for this, one for the player which has at least these attributes: first name and last name. Then you'll want to have a class for the team info which would have a Team name, maybe what country they're from, and a collection of players [List<Player>()] then the main for would simply have a list of teams [List<Team>()] and when a team is selected in the ComboBox (or ListBox) it would display the name in a label and the list of players in either a ComboBox or ListBox by looping the players collection, when you add a new player you would have to have a team selected first, you don't need a list of players on the form because that's available with each team.
Then you can add the matches thing on top of all of that, where you have at least two established teams and whatnot.

Conceptually does that all make sense?
 
Let's take a step back and analyze what all is going on with your code, first off you post about adding movies to a person's collection but all of the code you post has to do with sports teams and having players on it which is basically the same thing as a person having movies but it's a confusing thing to switch context like that.
But back to the code, I see where you're creating new "teams" and adding it to the teams collection, but I'm not seeing anywhere where you're adding a player to a team, you are however creating a player and adding it to the Players collection, but there's no team assignment in your code. This is all very confusing for us to try to step back and figure out what's really going on with your code, which might be why jmc is getting a little snippy.

So, what I would do is step back and without even considering the Form (where all the ListBoxes and stuff is) but think about the classes and how each would relate to the others. I'll begin with the teams and players for ya, you'll probably want two classes for this, one for the player which has at least these attributes: first name and last name. Then you'll want to have a class for the team info which would have a Team name, maybe what country they're from, and a collection of players [List<Player>()] then the main for would simply have a list of teams [List<Team>()] and when a team is selected in the ComboBox (or ListBox) it would display the name in a label and the list of players in either a ComboBox or ListBox by looping the players collection, when you add a new player you would have to have a team selected first, you don't need a list of players on the form because that's available with each team.
Then you can add the matches thing on top of all of that, where you have at least two established teams and whatnot.

Conceptually does that all make sense?
Additionally I have created an example project showing what I stated above.
 

Attachments

  • FotbollExample.zip
    26.4 KB · Views: 44
Status
Not open for further replies.
Back
Top Bottom