刷新Master-Detail gridcontrol

时间:2014-04-05 14:29:07

标签: devexpress entity

我有一个devexpress Master-View gridcontrol,绑定到Entity bindingsource。 以编程方式我更新了bindingsource上的一些记录,但Gridcontrol没有刷新新数据。 我使用以下方法:( GridviewMaster - 是Master View,GridviewChild - 是Detail视图)

      GridControl1.RefreshDataSource()
      GridControl1.MainView.RefreshData()
      GridControl1.DefaultView.RefreshData()
      GridViewMaster.RefreshData()
      GridViewChild.RefreshData()

但没有成功。我知道bindingsource已更新,但Gridcontrol却没有。只有当我关闭并再次打开表单时,才会更新gridcontrol。 我能做什么 ? (不再查询数据库) 谢谢 !         '

2 个答案:

答案 0 :(得分:1)

您是否尝试将其重新绑定到数据源?

GridViewMaster.DataSource = DataSource;
GridViewMaster.DataBind();

这将使用新数据重新加载表。

答案 1 :(得分:0)

偶然发现同样的问题,我想出的唯一方法是强行刷新受影响的行,然后崩溃并重新展开它们(如果它们首先被扩展 - 折叠的行不需要这样的东西):

        var rowsWhichNeedToBeRefreshed = ...; // find the master rows which are expanded using e.g. GetMasterRowExpanded()
        if (rowsWhichNeedToBeRefreshed.Any())
        {
            try
            {
                gridcontrol.SuspendLayout();
                rowsWhichNeedToBeRefreshed.ForEach(x =>
                {
                    gridview.CollapseMasterRow(x.Item1);
                    gridview.SetMasterRowExpanded(x.Item1, 0, expand: true);
                });
            }
            finally
            {
                gridcontrol.ResumeLayout(performLayout: true);
            }
        }