1 Attachment(s)
Re: serialization question
i have attached a screen shot of the playlist form. Hope it helps explain my problem
1 Attachment(s)
Re: serialization question
Quote:
Originally Posted by
beginner91
i have attached a screen shot of the playlist form. Hope it helps explain my problem
It is better to submit image files as jpegs or gifs, as not everyone can read docX files. For the benefit of those of us who either don't have an up-to-date Word, or don't know that docX files are effectively zip files :), here is the relevant image:
Re: serialization question
Quote:
or don't know that docX files are effectively zip file
...?
Re: serialization question
Quote:
Originally Posted by
BioPhysEngr
...?
It's true - change the extension to .zip and you can open it using unzip or some such application. That's how I extracted the image.
Re: serialization question
Re: serialization question
now that the image is sorted can someone help with my problem?
Re: serialization question
As far as I know there's no VS standard library containing Playlist. Mind givings us what you do in your add() method ?
Re: serialization question
ok here is all the code for you get a better idea of what i'm trying to do
Code:
namespace Playing_MP3_songs
{
public partial class CreatePlaylistForm : Form
{
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
bool paused = false;
ArrayList myPlaylistsCollection = new ArrayList();
public CreatePlaylistForm()
{
InitializeComponent();
// DirectoryInfo dinfo = new DirectoryInfo(@"C:\Users\Public\Music\Sample Music");
DirectoryInfo dinfo = new DirectoryInfo(@"C:\music");
FileInfo[] Files = dinfo.GetFiles("*.mp3");
foreach (FileInfo file in Files)
{
LibraryTracks.Items.Add(file.Name);
}
}
private void button2_Click(object sender, EventArgs e) //add track
{
foreach(string name in PlaylistTracks.Items )
{
if (LibraryTracks.SelectedItem.ToString() == name)
{
MessageBox.Show("Song already in playlist");
return;
}
}
PlaylistTracks.Items.Add(LibraryTracks.SelectedItem);
}
private void button3_Click(object sender, EventArgs e) //remove track
{
PlaylistTracks.Items.Remove(PlaylistTracks.SelectedItem);
}
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);
}
}
}
}
and looking at the image of what form the first listbox is populated from a folder called music. The second listbox is for the playlist. The add/remove buttons add or remove the songs to the second listbox. I want the create button to save the selection of songs in the second listbox and the name in the textbox.
I then have another form where I want the names of the playlists to be displayed in
Re: serialization question
Look at this code:
Code:
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);
}
}
You are creating a new Playlist and populating it correctly, but it is lost when the click handler finishes. You need to save it in a variable (i.e. a collection of playlists) outside this function.
Re: serialization question
ok thanks but how would I do that?
Re: serialization question
Quote:
Originally Posted by
beginner91
ok thanks but how would I do that?
Instead of having the Playlist temp a local variable inside the button click handler, make it a class field or property (so it has class scope).
Do you know how to declare a class field? E.g.
Code:
private PlayList _playList;
Re: serialization question
i ready made a class for playlist
Code:
namespace Playing_MP3_songs
{
class Playlist
{
private string name;
ArrayList list;
public Playlist(string name)
{
this.name = name;
list = new ArrayList();
}
public void addSong(string fileName)
{
list.Add(fileName);
}
}
}
Playlist is referring to this class
Re: serialization question
You have this data member in your class:
Code:
ArrayList myPlaylistsCollection = new ArrayList();
Shouldn't the playlists go in there :confused:
Re: serialization question
yes you are right. so how do i put the playlists in there?
Re: serialization question
Quote:
Originally Posted by
beginner91
yes you are right. so how do i put the playlists in there?
'Add' them. Look at the documention for ArrayList.
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?
Re: serialization question
Quote:
Originally Posted by
beginner91
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'
}
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
}
Re: serialization question
Quote:
Originally Posted by
beginner91
ok thanks so i added this line:
Code:
myPlaylistsCollection.Add(temp);
That's it. :)
Quote:
Originally Posted by
beginner91
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.
Re: serialization question
Quote:
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?
Re: serialization question
Quote:
Originally Posted by
beginner91
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.