[英]Refresh Grid Control DevExpress
我正在輪詢站點並更新我的數據源(SQLite表)。 該表在輪詢后立即正確更新。
XPCollection與該表關聯,並且XPCollection用作網格控件的數據源。
我的問題是:網格的數據未更新。 我必須打開和關閉應用程序才能看到他的新數據反映在網格中。
我嘗試了刪除數據源,刷新數據源的所有組合,但是似乎沒有任何效果。
以下是我用於輪詢和刷新Grid的代碼,
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;
}
}
任何幫助將不勝感激,這正在引起頭痛。
您是否嘗試致電
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());
}
}
Édit1
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());
}
以下代碼解決了我的問題。
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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.