2016-03-15 92 views
0

我在輪詢一個網站並更新我的數據源(SQLite表)。在投票結束後,表格會正確更新。刷新網格控件DevExpress

XPCollection與表關聯,並且XPCollection用作網格控件的數據源。

我的問題是:網格的數據沒有更新。我必須打開和關閉應用程序才能看到他在網格中反映的新數據。

我已嘗試刪除數據源,刷新數據源,但似乎沒有任何工作的所有組合。

下面是我對輪詢和刷新網格代碼,

private async void WaitForXSeconds() 
    { 
     for (int i = 0; i < 100; i++) 
     { 
      await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(60)); 
      // do something after x seconds! 
      // Updates the DB with new/modified data 
      LoadDailyButton_Click(null, null); 

      BestGrid.DataSource = null; 

      BestGrid.DataSource = BestCollection; 

      string starttime = System.DateTime.Now.ToString(); 
      CycleResultsListBox.Items.Add("Cycle Started : " + starttime.ToString()); 
     } 
    } 

這裏是什麼我的課看起來像一個部分片段:

public class BestData : XPLiteObject 
{ 
    private int id; 

    [Key(true)] 
    public int Id 
    { 
     get { return id; } 
     set 
     { 
      id = value; 
     } 
    } 

    private DateTime gameDate; 

    public DateTime GameDate 
    { 
     get { return gameDate; } 
     set 
     { 
      gameDate = value; 
     } 
    } 

    private string hometeamName; 

    public string HomeTeamName 
    { 
     get { return hometeamName; } 
     set 
     { 
      hometeamName = value; 
     } 
    } 

任何幫助,將不勝感激,這個人是引起頭痛。

+0

您是否在官方DevExpress論壇上嘗試過類似問題的答案? https://www.devexpress.com/Support/Center/Question/Details/Q443034 –

回答

0

您是否試圖撥打電話

BestGrid.DataBind(); BestGrid.DataSource = XXX

private async void WaitForXSeconds() 
{ 
    for (int i = 0; i < 100; i++) 
    { 
     await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(60)); 
     // do something after x seconds! 
     // Updates the DB with new/modified data 
     LoadDailyButton_Click(null, null); 
     BestGrid.DataSource = null; 
     BestGrid.DataSource = BestCollection; 
     Bestgrid.DataBind(); 
     string starttime = System.DateTime.Now.ToString(); 
     CycleResultsListBox.Items.Add("Cycle Started : " + starttime.ToString()); 
    } 
} 

編輯1

gridControl1.BeginUpdate(); 
     try 
     { 
      gridView1.Columns.Clear(); 
      gridControl1.DataSource = null; 
      gridControl1.DataSource = <newDataSource>; 
     } 
     finally 
     { 
      gridControl1.EndUpdate(); 
     } 

對於你以後:

for (int i = 0; i< 100; i++) 
{ 
    await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(60)); 
    // do something after x seconds! 
    // Updates the DB with new/modified data 
    LoadDailyButton_Click(null, null); 

    gridControl1.BeginUpdate(); 

    BestGrid.DataSource = null; 
    BestGrid.DataSource = BestCollection; 

    gridControl1.EndUpdate(); 

    string starttime = System.DateTime.Now.ToString(); 
    CycleResultsListBox.Items.Add("Cycle Started : " + starttime.ToString()); 
} 
+0

BestGrid上沒有「DataBind」方法。 –

+0

我試過了BestCollection.Reload()和BestGrid.Refresh()。不用找了。 –

+0

看我的編輯在我以前的帖子 – pix

0

下面的代碼已經固定我的問題。

private async void WaitForXSeconds() 
    { 
     for (int i = 0; i < 100; i++) 
     { 
      await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(300)); 
      // do something after x seconds! 
      // Updates the DB with new/modified data 
      LoadDailyButton_Click(null, null); 


      gridView2.CollapseAllDetails(); 
      BestGrid.DataSource = null; 
      session1.DropIdentityMap(); 
      BestCollection.Reload(); 
      BestGrid.DataSource = BestCollection; 

      string starttime = System.DateTime.Now.ToString(); 
      CycleResultsListBox.Items.Add("Cycle Started : " + starttime.ToString()); 
     } 
    } 

這是我用來保存數據的代碼;

using (var uow = new UnitOfWork(xsession.DataLayer)) 
        { 
         BestData getSingleRec = new XPCollection<BestData>(uow, CriteriaOperator.Parse("[HomeTeamName]=? AND [GameDate]=?", tempStr5.ToString(), Convert.ToDateTime(gameDate))).FirstOrDefault(); 


           getSingleRec.awayR = Convert.ToInt16(tempStr7); 
           getSingleRec.homeR = Convert.ToInt16(tempStr8); 
           getSingleRec.awayML = tempStr2; 
           getSingleRec.homeML = tempStr3; 


          getSingleRec.Save(); 
          uow.CommitChanges(); 

        } 
+0

正是我所說的。您的Bestcollection出現問題。 你可以請嘗試代碼,我把我的編輯,並添加zour BestCollection.Reload()befor BestGrid.DataSource = BestCollection; 如果在網格上使用BeginUpdate和EndUpdate方法,我不確定是否需要DropIdentityMap。 而你的gridview2?您之前沒有顯示任何與此網格相關的代碼。 下次嘗試顯示更多代碼。 – pix