2015-05-22 102 views
0

另一個問題: 我們現在正在使用ModLoader,並具有瀏覽功能,該功能可以在常規ListView下正常工作。但是我們需要在SubItem上顯示圖像,所以ObjectListView非常方便。如何正確添加項目到ObjectListView?

一旦我啓動程序,我得到了InvalidCastException,因爲我沒有使用SetObjects(),所以我建立了一個類型爲TroveSaurusMods的List以及一個名爲相同的類。添加項目可以正常工作,但項目不會顯示在OLV中。有人可以幫我弄這個嗎?然後,幫助我的圖像顯示?

這裏是我加入的項目代碼:

private void getMods(ref ObjectListView location) 
    { 
     var lstItems = new List<TroveSaurusMod>(); 
     logger.log("Trying to add mods from TroveSaurus to the list...", Logger.logLevel.INFO); 
     try 
     { 
      using (var webClient = new System.Net.WebClient()) 
      { 
       var jsonWeb = webClient.DownloadString("API LINK HERE"); 
       string json = js.Deserialize(new JsonTextReader(new System.IO.StringReader(jsonWeb))).ToString(); 
       jtr = new JsonTextReader(new System.IO.StringReader(json)); 
       JArray a = JArray.Parse(json); 
       for (int i = 0; i < a.Count; i++) 
       { 
        var element = a[i]; 
        JsonTextReader arRead = new JsonTextReader(new System.IO.StringReader(element.ToString())); 
        OLVListItem item = null; 
        lvBrowse.SmallImageList = imgSmall; 
        while (arRead.Read()) 
        { 
         if (arRead.Value != null) 
         { 
          if (arRead.Value.ToString() == "id") 
          { 
           item = new OLVListItem(arRead.ReadAsString()); 
          } 
          if (arRead.Value.ToString() == "name") 
          { 
           item.SubItems.Add(arRead.ReadAsString()); 
          } 
          if (arRead.Value.ToString() == "author") 
          { 
           item.SubItems.Add(arRead.ReadAsString()); 
          } 
          if (arRead.Value.ToString() == "type") 
          { 
           item.SubItems.Add(arRead.ReadAsString()); 
          } 
          if (arRead.Value.ToString() == "subtype") 
          { 
           item.SubItems.Add(arRead.ReadAsString()); 
          } 
          if (arRead.Value.ToString() == "fileid") 
          { 
           item.SubItems.Add(arRead.ReadAsString()); 
          } 
          if (arRead.Value.ToString() == "filedate") 
          { 
           item.SubItems.Add(UnixTimeStampToDateTime(Double.Parse(arRead.ReadAsString())).ToShortDateString()); 
          } 
         } 
        } 
        //item.ImageIndex = i; 

        lstItems.Add(new TroveSaurusMod(item.Text, item.SubItems[1].Text, item.SubItems[2].Text, item.SubItems[3].Text, item.SubItems[4].Text, item.SubItems[5].Text, item.SubItems[6].Text)); 
        logger.log("Successfully added " + item.Text + " to the list!", Logger.logLevel.FINE); 
       } 
       lvBrowse.SetObjects(lstItems.ToString()); 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("Unable to retrieve mod list from TroveSaurus! Please check your internet connection!", "Error parsing mods"); 
      logger.log(ex.StackTrace.ToString(), Logger.logLevel.ERROR); 
      throw; 
     } 
    } 

而且我的課TroveSaurusMods:

public class TroveSaurusMod 
{ 
    public string Id { get; set; } 
    public string Name { get; set; } 
    public string Author { get; set; } 
    public string Type { get; set; } 
    public string SubType { get; set; } 
    public string FileId { get; set; } 
    public string FileDate { get; set; } 

    public TroveSaurusMod(string id, string name, string author, string type, string subtype, string fileId, string fileDate) 
    { 
     Id = id; 
     Name = name; 
     Author = author; 
     Type = type; 
     SubType = subtype; 
     FileId = fileId; 
     FileDate = fileDate; 
    } 
} 

我從來沒有與名單的​​工作,只使用ListView。請告訴我,假如我做錯了什麼,什麼我需要改變:) 感謝

編輯:找到了答案......需要設置AspectName:d

回答

0

好吧,我才發現,那我必須爲每列設置AspectName ...對不起:O

相關問題