Object to List<Song>
I am currently using ObjectListView, and right now, i'm trying to get it so if i click on a开发者_JAVA技巧n object (row), it will give me information about that song (in list form).
Currently, I have a custom list:
public Song(string title, string artist, string album, string genre, string time, int playcount, string location)
{
this.Title = title;
this.Artist = artist;
this.Album = album;
this.Genre = genre;
this.Time = Convert_Time(Convert.ToInt32(time));
this.PlayCount = playcount;
this.Location = Convert_Location(location) ;
}
I want to be able to convert an object into that list form.
private void olvMain_SelectedIndexChanged(object sender, EventArgs e)
{
object thing = olvMain.GetItem(olvMain.SelectedIndex).RowObject;
}
Currently it returns Genesis.Song, which happens to contain all the data of the selected song. However, I can't access the information in object form. Is there anyway way to convert/ extract it?
Just a guess, but are you able to simply cast the object
to your Song
type?
private void olvMain_SelectedIndexChanged(object sender, EventArgs e)
{
Song thing = (Song)olvMain.GetItem(olvMain.SelectedIndex).RowObject;
}
Does
Song thing = (Song)olvMain.GetItem(olvMain.SelectedIndex).RowObject
work?
精彩评论