我正在轮询网站并更新我的数据源(SQLite表)。该表在轮询后立即正确更新。
XPCollection与表关联,XPCollection用作网格控件的DataSource。
我的问题是: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;
}
}
任何帮助都会受到赞赏,这一点令人头疼。
答案 0 :(得分: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());
}
}
É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());
}
答案 1 :(得分: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();
}