CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Join Date
    Jan 2009
    Posts
    596

    Re: serialization question

    Quote Originally Posted by beginner91 View Post
    yes you are right. so how do i put the playlists in there?
    'Add' them. Look at the documention for ArrayList.

  2. #17
    Join Date
    Mar 2012
    Posts
    99

    Re: serialization question

    i know there is this way to add:
    Code:
    myPlaylistsCollection .add(something);
    and you repeat that line for each item
    put i don't want to manually add each item like that
    so could you show me how to add them?

  3. #18
    Join Date
    Jan 2009
    Posts
    596

    Re: serialization question

    Quote Originally Posted by beginner91 View Post
    i know there is this way to add:
    Code:
    myPlaylistsCollection .add(something);
    and you repeat that line for each item
    put i don't want to manually add each item like that
    so could you show me how to add them?
    You don't need to 'repeat that line for each item'. The problem is that you are making a temp Playlist, but not putting it in your playlist collection (myPlaylistsCollection). I.e. you only have one item (the playlist) to add.
    Code:
            ArrayList myPlaylistsCollection = new ArrayList();
    
            private void button1_Click(object sender, EventArgs e) //create playlist
            {
                Playlist temp = new Playlist(textBoxPlaylist.Text);
                foreach(string name in PlaylistTracks.Items)
                {
                    temp.addSong(name);
               
                }
                // Add 'temp' to 'myPlaylistsCollection'
            }

  4. #19
    Join Date
    Mar 2012
    Posts
    99

    Re: serialization question

    ok thanks so i added this line:
    Code:
    myPlaylistsCollection.Add(temp);
    now i want to display the playlist names in a listbox on the first form
    its just an empty listbox right now:
    Code:
    private void listBoxPlaylist_SelectedIndexChanged(object sender, EventArgs e)
            {
                //need to display the playlists created
            }

  5. #20
    Join Date
    Jan 2009
    Posts
    596

    Re: serialization question

    Quote Originally Posted by beginner91 View Post
    ok thanks so i added this line:
    Code:
    myPlaylistsCollection.Add(temp);
    That's it.

    Quote Originally Posted by beginner91 View Post
    now i want to display the playlist names in a listbox on the first form
    its just an empty listbox right now:
    Code:
    private void listBoxPlaylist_SelectedIndexChanged(object sender, EventArgs e)
            {
                //need to display the playlists created
            }
    You just need to loop through myPlaylistsCollection, getting the names of each Playlist in turn. Then add these names to the listbox.

    If you don't know how to do these steps, please look up the documentation on MSDN. You'll need to look up ArrayList and ListBox.

    Forums are better for things which can't be easily googled.

  6. #21
    Join Date
    Mar 2012
    Posts
    99

    Re: serialization question

    You just need to loop through myPlaylistsCollection, getting the names of each Playlist in turn.
    ok I tried adding a loop but it doesn't recognize myPlaylistsCollections since its in a different form. Do i need to add something so it can read the code from the second form?

  7. #22
    Join Date
    Jan 2009
    Posts
    596

    Re: serialization question

    Quote Originally Posted by beginner91 View Post
    ok I tried adding a loop but it doesn't recognize myPlaylistsCollections since its in a different form. Do i need to add something so it can read the code from the second form?
    From the questions you are asking, it seems that you don't have a good understanding of the basics. I really think you would benefit from working through some tutorials on collections, forms and controls. There are plenty online - just google them.

    In particular, look for a tutorial showing how to return results from a Form. That will help you with your current question.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured