Delphi 刷新查询/cxGrid
使用delphixe2 我正在编写一个使用cxGrids并链接到查询/数据源的软件包 单击按钮后,如何刷新查询以确保cxGrids中的记录是最新的Delphi 刷新查询/cxGrid,delphi,delphi-xe2,sybase-asa,Delphi,Delphi Xe2,Sybase Asa,使用delphixe2 我正在编写一个使用cxGrids并链接到查询/数据源的软件包 单击按钮后,如何刷新查询以确保cxGrids中的记录是最新的 此外,如果某条记录在cxGrid上突出显示,则它必须记住该记录,并且不会重置回网格顶部。关闭并打开cxGrid后面的数据集,以确保您拥有最新数据 dataset.close; dataset.open; 如果您需要记住当前记录并将光标放回记录上,请使用书签,如下面的链接所示 如果您不想使用书签,可以使用dataset.locate方法。 存储记录
此外,如果某条记录在cxGrid上突出显示,则它必须记住该记录,并且不会重置回网格顶部。关闭并打开
cxGrid
后面的数据集,以确保您拥有最新数据
dataset.close;
dataset.open;
如果您需要记住当前记录并将光标放回记录上,请使用书签,如下面的链接所示
如果您不想使用书签,可以使用dataset.locate方法。
存储记录的主键,刷新后,使用dataset.locate(dataset.fieldbyname('PK').AsDataType)返回该记录
使用locate方法可能是一种更具可读性/优雅的工作方式。cxGridTableView.Navigator
有一个刷新按钮,可以执行您想要的操作
如果您想使用自己的按钮进行刷新,可以调用cxGridTableView.DataController.RefreshExternalData
对于devexpress的cxgrid,收受赌注者对于恢复选择是一个糟糕的解决方案,您可以使用cxStatusKeeper(您可以从devexpress的支持中心下载的it公共单元)
您的视图是否处于网格模式
和/或同步模式
?您可以在“DataController.DataModeController”中检查,为了完整性,我将添加DevExpress文章的链接:
{Init the component for restore selection}
FGridStatus := TcxGridDBTableKeeper.Create(self);
FGridStatus.LoadExpanding := False;
FGridStatus.LoadSelection := True;
FGridStatus.LoadFocus := True;
FGridStatus.LoadTopRecord := False;
FGridStatus.LoadWithDetails := False;
FGridStatus.LoadFocusedView := True;
FGridStatus.LoadFocusedItem := True;
FGridStatus.View := gvTableElementi;
{save the current items}
FGridStatus.Store;
{restore the selection}
if FGridStatus.GridStored then
FGridStatus.Restore;