cxGrid使用说明

2026/4/23 7:21:46

激活内置编辑控件

1) .Controller.EditingController.ShowEdit();

2) .Controller.EditingController.StartEditShowingTimer(); 3) .Controller.EditingItem := ; 4) .Editing := True;

隐藏内置编辑控件

.Controller.EditingController.HideEdit(True);

===========================================================================

移除一个分组列

.GroupIndex := -1; .Visible := True;

===========================================================================

保存修改到数据库

procedure .FormClose(Sender: TObject; var Action: TCloseAction); begin

if (.FocusedView <> nil) and (.FocusedView.DataController.EditState <> []) then .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

.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;

Level.Name := 'SomeLevelName'; // Creates a View

View := Grid.CreateView(TcxGridDBTableView) as TcxGridDBTableView; View.Name := 'SomeViewName'; // … and binds it to the Level Level.GridView := View;

// Hooks up the View to the data

View.DataController.DataSource := SomeDataSource; // … and creates all columns

View.DataController.CreateAllItems; end;

此楼回复Re:

--------------------------------------------------------------------------------

======================================================================

获得Group Footer合计行对应的记录

procedure TForm1.cxGrid1DBTableView1CustomDrawFooterCell( Sender: TcxGridTableView; ACanvas: TcxCanvas;

AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean); var

ALevel, ADataGroupIndex: Integer;

AGridRecord, AGroupRecord: TcxCustomGridRecord;


cxGrid使用说明.doc 将本文的Word文档下载到电脑
搜索更多关于: cxGrid使用说明 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219