cxGrid控件功能很强大,有许多方法及属性,其中有一个属性gridmode
当你设置gridmode=true时,会提高查询速度,为false时则反之,为什么如此,在网上有相关的贴子
详见:详见:http://topic.youkuaiyun.com/t/20041025/08/3487114.html
************************************************
Specifies whether a lookup grid is in GridMode.
property GridMode: Boolean;
Description
You can use the GridMode property to speed up working with large lookup datasets (datasets displayed in the dropdown).
When Grid Mode is not set, a lookup editor loads all records into memory upon connecting to a dataset. For large lookup datasets, this can result in lowering performance.
Setting the GridMode property to True enables caching of edit values and display texts. If required edit value and display text are not present in the cache, they are obtained from the lookup dataset and stored in the cache for future use. This considerably increases the performance, when the lookup combobox is used as an in-place editor in a Grid control.
Grid Mode imposes some restrictions on working with the editor and lookup dataset:
Grid Mode imposes some restrictions on working with the editor and lookup dataset:
?the edit box of the lookup editor displays a value (TField.AsString) rather than display text of the field addressed by the ListFieldItem property.
?similarly, an incremental search is performed against field values rather than display texts.
?you must not navigate the lookup dataset programmatically as this can conflict with the Locate method used by the editor itself.
The default value of the GridMode property is False.
********************************************
当设置gridmode=true时,则在cxGrid上设置的filtering,sorting,footer中的合计信息均无效(几天前做一个模块时发现的)。
我要实现的功能如下:
1.在cxgrid上显示一些信息(连接数据集很容易实现)
2.每列要有filter的功能(每一列的filtering=true)
3.要有一个合计列(footer,合计的记录数,数量,金额等)
4.可以选择部分信息,然后统计更新某一列或几列的值
其它的还有许多,主要的功能是想把对于Excel操作的相关操作用程序来实现,要达到信息共享,方便统计查询等但最主要的用程序不能增加工作量(与Excel相比)
在實現過程想了很多辦法為子操作能够快速簡單,處理過程
1.將一些繁瑣的查詢條件進行分析,然后進行分類,使其簡單化
2.對于复制粘貼等,采用了對像,指針及類似Excel的操作方法實現
3.增加多种條件的篩選及統計,做相關的統計報表避免重复的工作
......
在做的過程中有一個問題,就是在選擇性更新過程中如何刷新使用戶能够立刻看到結果
第一种方法:
增加刷新的方法,利用update語句來實現更新,然后commit,最后根據選定的條件重新刷新界面,這是我用的比較多的,但目前不方便,刷新后,我看不到我正在更改的是哪條或哪几條記錄了(如果很多數據)
第二种方法:
利用dataset的edit,post方法進行更新
a.
for i:= 0 to DSRFTDAVEW.Controller.SelectedRowCount-1 do
begin
DSRFTDAVEW.DataController.FocusSelectedRow(i); //这种方法需要设置 gridmode=true,但此时会将filtering,sorting,footer等失效
OraQuery1.Edit;
OraQuery1.FieldByName('FeatSN').Value := SerialNO;
end;
這樣要首先設置gridmode=true,但就會出現最開始提到的問題
我試著在修改時將gridmode=true,當修寇成后再將其gridmode=false,雖然可以修改,但是在修改過程中如果利用某列的filtering先篩選一些數據后,就會出現問題。
b.
利用DSRFTDAVEW.Controller.FocusedRow := DSRFTDAVEW.Controller.SelectedRows[i];來獲取數據的焦點即用cxgridview的controller來實現,這樣就可以避免gridmode=true的衝突。
下面是在网上找到的相關的資料
2009-03-27 21:31
激活内置编辑控件
1) <aView>.Controller.EditingController.ShowEdit(<aColumn>);
2) <aView>.Controller.EditingController.StartEditShowingTimer(<aColumn>);
3) <aView>.Controller.EditingItem := <aColumn>;
4) <aColumn>.Editing := True;
隐藏内置编辑控件
<aView>.Controller.EditingController.HideEdit(True);
===========================================================================
移除一个分组列
<aColumn>.GroupIndex := -1;
<aColumn>.Visible := True;
===========================================================================
保存修改到数据库
procedure <aForm>.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if (<aGrid>.FocusedView <> nil) and (<aGrid>.FocusedView.DataController.EditState <> []) then
<aGrid>.FocusedView.DataController.Post;
end;
============================================================================
设置内置右键菜单
内置右键菜单包括二个菜单:cxGridStdHeaderMenu, TcxGridStdFooterMenu
uses cxGridStdPopupMenu;
procedure TForm1.cxGridPopupMenu1Popup(ASenderMenu: TComponent;
AHitTest: TcxCustomGridHitTest; X, Y: Integer; var AllowPopup: Boolean);
begin
if ASenderMenu is TcxGridStdHeaderMenu then
TcxGridStdHeaderMenu(ASenderMenu).OnPopup := StdHeaderMenuPopup;
end;
procedure TForm1.StdHeaderMenuPopup(Sender: TObject);
var
I: Integer;
begin
with TcxGridStdHeaderMenu(Sender).Items do
for I := 0 to Count - 1 do
if Items[I].Caption = 'Group By Box' then
begin
Items[I].Enabled := False;
System.Break;
end
end;
===========================================================================
得到选中记录的值
1) View.DataController.DataModeController.GridMode = False时
RecIdx := View.Controller.SelectedRecords[i].RecordIndex;
ColIdx := View.DataController.GetItemByFieldName(AFieldName).Index;
OutputVal := View.DataController.Values[RecIdx, ColIdx];
//RecID := View.DataController.GetRecordId(RecIdx);
//OutputVal := ADataSet.Lookup(View.DataController.KeyFieldNames, RecID, AFieldName);
2) View.DataController.DataModeController.GridMode = True时
Bkm := View.DataController.GetSelectedBookmark(ASelectedRecordIndex);
if ADataSet.BookmarkValid(TBookmark(Bkm)) then
begin
ADataSet.Bookmark := TBookmark(Bkm);
OutputVal := ADataSet.FieldByName(AFieldName).Value;
end;
View.BeginUpdate;
View.DataController.BeginLocate;
try
// make changes here…
finally
View.DataController.EndLocate;
View.EndUpdate;
end;
=============================================================
在GridMode禁用内置的右键Footer菜单
uses cxGridStdPopupMenu;
procedure cxGridPopupMenuOnPopup(...)
begin
if (ASenderMenu is TcxGridStdFooterMenu) and
<GridView>.DataController.DataModeController.GridMode then
AllowPopup := False;
end;
==============================================================
主从表任何时候只能展开一个组
procedure TForm1.ADetailDataControllerCollapsing(
ADataController: TcxCustomDataController; ARecordIndex: Integer;
var AAllow: Boolean);
var
I: Integer;
C: Integer;
begin
AAllow := False;
C := 0;
for I := 0 to ADataController.RecordCount - 1 do
begin
if ADataController.GetDetailExpanding(I) then
Inc(C);
if C > 1 then
AAllow := True;
end;
end;
procedure TForm1.ADetailDataControllerExpanding(
ADataController: TcxCustomDataController; ARecordIndex: Integer;
var AAllow: Boolean);
begin
ADataController.CollapseDetails;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
cxGrid1DBTableView1.DataController.OnDetailExpanding := ADetailDataControllerExpanding;
cxGrid1DBTableView1.DataController.OnDetailCollapsing := ADetailDataControllerCollapsing;
end;
=================================================================
动态创建层次(Level)和视图(View)
var
Grid: TcxGrid;
Level: TcxGridLevel;
View: TcxGridDBTableView;
begin
// Creates a Grid instance
Grid := TcxGrid.Create(SomeOwner);
Grid.Parent := SomeParent;
// Creates a Level
Level := Grid.Levels.Add;