2013-04-07 61 views
0

試圖在列表框中打印歌曲刺激。我試着將它們添加爲項目,但只是打印windowsform1.cs。我是否必須轉換項目,或者他們是我需要爲列表框打印字符串和int的函數。如何在列表框中顯示列表

private string title; 
private string album, title, artist, genre; 
private int length; 

private void List_Click(object sender, EventArgs e) 
{ 
    MDB.listAllSongs(listBox1.Items); 

} 

public void listAllSongs(IList list) 
{ 
    List<Song> allSongs = new List<Song>(); 
    foreach (Album album in albums) 
    { 
     album.listSongs(allSongs); 
    } 

    foreach (Song song in allSongs) 
    { 
     list.Add(song.ToString()); 
    } 
} 

public void listSongs(List<Song> list) 
{ 
    foreach (Song song in songs) 
    { 
     list.Add(song); 
    } 
} 

回答

1

您需要實現toString()方法中的宋級,來回報您的歌曲的標題:

public string toString() 
{ 
    return title; 
} 
+0

是啊,我已經做到了這一點,但它仍然是未來與相同事情 – user2224223 2013-04-07 14:49:39