I'm polling a site and updating my datasource (SQLite table). The table gets updated correctly right after the poll.
An XPCollection is associated with the table and the XPCollection is used as the DataSource for the Grid Control.
My problem is: the Grid's data is not updated. I must open and close the application to see he new data reflected in the Grid.
I have tried all combinations of removing data source, refreshing datasource, but nothing seems to work.
Below is my code for polling and refreshing the 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());
}
}
Here is a partial snippet of what my class look like:
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;
}
}
Any help would be appreciated, this one is causing headaches.
Did you try to call
BestGrid.DataBind(); after 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());
}
}
Édit 1
gridControl1.BeginUpdate();
try
{
gridView1.Columns.Clear();
gridControl1.DataSource = null;
gridControl1.DataSource = <newDataSource>;
}
finally
{
gridControl1.EndUpdate();
}
For you:
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());
}
The following code has fixed my problem.
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());
}
}
Here is the code I use to save the data;
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.