繁体   English   中英

刷新网格控件DevExpress

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM