【问题标题】:How to display a list in a listbox如何在列表框中显示列表
【发布时间】:2013-04-07 13:57:45
【问题描述】:

尝试在列表框中打印歌曲。我尝试将它们添加为项目,但这只是打印 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);
    }
}

【问题讨论】:

    标签: c# winforms list listbox


    【解决方案1】:

    您需要在 Song 类中实现 toString() 方法,以返回歌曲的标题:

    public string toString()
    {
        return title;
    }
    

    【讨论】:

    • 是的,我已经这样做了,但它仍然想出同样的事情
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-21
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多