2009-10-22 81 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 

工作?