2009-10-22 83 views
0

我目前正在使用ObjectListView,现在,我试图得到它,所以如果我点击一个对象(行),它会给我关于该歌曲(列表形式)的信息。对象列表<Song>

目前,我有一个自定义列表:

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) ; 
     } 

我希望能够将对象转换成列表形式。

private void olvMain_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     object thing = olvMain.GetItem(olvMain.SelectedIndex).RowObject;   
    } 

目前它返回Genesis.Song,它恰好包含所选歌曲的所有数据。但是,我无法以对象形式访问信息。有无论如何转换/提取它?

回答

4

只是一个猜测,但你能简单地投object到您的Song类型?

private void olvMain_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    Song thing = (Song)olvMain.GetItem(olvMain.SelectedIndex).RowObject; 
} 
+0

是的......我不能相信我忘了:/ tysm:P – Mike 2009-10-22 22:52:12

1

是否

Song thing = (Song)olvMain.GetItem(olvMain.SelectedIndex).RowObject 

工作?