2016-01-29 37 views
0

使用TweetSharp我正在計算關注者列表。我怎樣才能收回到ListBox如何在列表框中取消ListFollower?

下面是代碼:

var options = new ListFollowerIdsOfOptions() { ScreenName = "PutinRF" }; 
do 
{ 
    if (cursor != null) 
     options.Cursor = cursor; 

    var followersList = ts.ListFollowerIdsOf(options); 

    //listBox1.Items.AddRange(followersList.ToArray()); 

    cursor = followersList.NextCursor; 

} while (cursor != 0); 

回答

1

嘗試使用DataSource property

listBox1.DataSource = followersList; 

還是看下面的實現:

var allIds = new List<long>(); 
var options = new ListFollowerIdsOfOptions() { ScreenName = "PutinRF" }; 
var followersIds = ts.ListFollowerIdsOf(options); 
while (followersIds.NextCursor != 0) 
{ 
    options.Cursor = followersIds.NextCursor; 
    allIds.AddRange(followersIds); 
} 
listBox1.DataSource = allIds; 
+0

錯誤:System.OutOfMemoryException。 line:allIds.AddRange(followersIds); –

+0

@ArtemOlegovich請參閱[本文](http://stackoverflow.com/questions/8563933/c-sharp-out-of-memory-exception)。你嘗試調試它嗎?列表中有多少項?例如: – Marusyk

+0

:{ScreenName =「PutinRF」,Count = 20}。同樣的錯誤=/ –

0

我的決定:

  var options = new ListFollowerIdsOfOptions { ScreenName = "PutinRF" }; 
      List<long> All_ods = new List<long>(); 
      TwitterCursorList<long> followerIDS = ts.ListFollowerIdsOf(options); 
      while(followerIDS.NextCursor!=null) 
      { 
       options.Cursor = followerIDS.NextCursor; 

       All_ods.AddRange(followerIDS.ToArray()); 
       //listBox1.Items.Add(All_ods.ToArray()); 
       listBox1.DataSource = All_ods; 
       label1.Text = "Получено: " + listBox1.Items.Count.ToString(); 
       break; 
      } 
+0

此解決方案與上述答案類似。我認爲在while設置DataSource是不正確的 – Marusyk

相關問題