private void button1_Click(object sender, EventArgs e)
{
var trackList = new List<Track>();
trackList.Add(new Track{ TrackID = 1234, Name = "I'm Gonna Be (500 Miles)", Artist = "The Proclaimers(I)", Album = "Finest(I)", PlayCount = 10, SkipCount = 1 });
trackList.Add(new Track { TrackID = 5678,Name = "I'm Gonna Be (1000 Miles)",Artist = "The Proclaimers(II)",Album = "Finest(II)", PlayCount = 20,SkipCount = 2});
trackList.Add(new Track { TrackID = 9101,Name = "I'm Gonna Be (2000 Miles)",Artist = "The Proclaimers(III)",Album = "Finest(II)", PlayCount = 40,SkipCount = 3});
trackList.Add(new Track { TrackID = 1213,Name = "I'm Gonna Be (4000 Miles)",Artist = "The Proclaimers(IV)",Album = "Finest(IV)", PlayCount = 80,SkipCount = 4});
//How to sort based on column name:Album
//something like this below.
trackList.Sort(trackList([0 4]);
//How to remove rows after search items in a column based on some criteria
trackList.RemoveAll(Album => Album.Contains("(II)"));
//How to Populate resuts in a listbox
//listBox1.DataSource = trackList();
}
public class Track
{
public int TrackID { get; set; }
public string Name { get; set; }
public string Artist { get; set; }
public string Album { get; set; }
public int PlayCount { get; set; }
public int SkipCount { get; set; }
}
如何根据列名进行排序:相册
在列中查找项目并删除这些行。
结果应放在列表框中,或者可以创建新列表。
答案 0 :(得分:5)
您可以使用LINQ:
trackList = trackList
.Where(t => !t.Album.Contains("(II)"))
.OrderBy(t => t.Album)
.ToList();
顺便说一下,它不是多维列表,而是List<Track>
。