delphi控件cxGrid用法大全(5)

来源:网络收集 时间:2025-07-26 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xuecool-com或QQ:370150219 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

end;

**************************************************************************** 41 得到选中记录的值 解决:

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;

**************************************************************************** 42 在GridMode禁用内置的右键Footer菜单 解决:

uses cxGridStdPopupMenu;

procedure cxGridPopupMenuOnPopup(...) begin

if (ASenderMenu is TcxGridStdFooterMenu) and

.DataController.DataModeController.GridMode then AllowPopup := False; end;

**************************************************************************** 43 主从表任何时候只能展开一个组 解决:

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;

**************************************************************************** 44 动态创建层次(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;

**************************************************************************** 45 获得Group Footer合计行对应的记录 解决:

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

AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean); var

ALevel, ADataGroupIndex: Integer;

AGridRecord, AGroupRecord: TcxCustomGridRecord; begin

if AViewInfo is TcxGridRowFooterCellViewInfo and // Row footer

(TcxGridDBColumn(AViewInfo.Column).DataBinding.FieldName = 'Area') then // Area column begin

AGridRecord:= TcxGridRowFooterCellViewInfo(AViewInfo).GridRecord; ALevel:= TcxGridRowFooterCellViewInfo(AViewInfo).Container.GroupLevel;

ADataGroupIndex:=Sender.DataController.Groups.DataGroupIndexByRowIndex[AGridRecord.Index]; if ADataGroupIndex <> -1 then begin

AGroupRecord := AGridRecord;

while AGroupRecord.Level <> ALevel do AGroupRecord := AGroupRecord.ParentRecord; AViewInfo.Text := AGroupRecord.DisplayTexts[0]; end; end; end;

**************************************************************************** 46 访问过滤之后的记录 解决: var

I: Integer; begin

Memo1.Lines.Clear;

with cxGrid1DBTableView1.DataController do for I := 0 to FilteredRecordCount - 1 do

Memo1.Lines.Add(DisplayTexts[FilteredRecordIndex[I], 0]); end;

**************************************************************************** 47 获得单元的Font 解决:

cxGrid1DBTableView1.ViewInfo.RecordsViewInfo.Items[1].GetCellViewInfoByItem( cxGrid1DBTableView1Company).EditViewInfo.Font;

**************************************************************************** 48 根据Level名称找到Level对象 解决:

function GetLevelByName(AGrid: TcxGrid; ALevelName: string): TcxGridLevel;

function LoopThroughLevels(ALevel: TcxGridLevel; ALevelName: string): TcxGridLevel; var

I: Integer; begin

Result := nil;

for I := 0 to ALevel.Count - 1 do begin

if ALevel[I].Name = ALevelName then begin

Result := ALevel[I]; Exit; end;

if ALevel[I].Count > 0 then begin

Result := LoopThroughLevels(ALevel[I], ALevelName); if Result <> nil then Exit; end; end; end; var

I: Integer; begin

Result := nil;

for I := 0 to AGrid.Levels.Count - 1 do begin

if AGrid.Levels[I].Name = ALevelName then begin

Result := AGrid.Levels[I]; Exit; end;

if AGrid.Levels[I].Count > 0 then begin

Result := LoopThroughLevels(AGrid.Levels[I], ALevelName); if Result <> nil then Exit; end; end; end;

**************************************************************************** 49 指定Filter Builder打开/保存过滤文件的默认路径 解决: uses

..., cxFilterControlDialog;

procedure TForm.GridView1FilterControlDialogShow( Sender: TObject); begin

TfmFilterControlDialog(Sender).OpenDialog.InitialDir := 'D:/' end;

**************************************************************************** 50 保存/恢复带汇总行的布局

.StoreToIniFile('c:\\Grid.ini', True, [gsoUseSummary]);

.RestoreFromIniFile(,True,False {or True, optional},[gsoUseSummary]);

**************************************************************************** 51 取消过滤时移到第一行 解决: uses

cxCustomData;

procedure TYour_Form.AViewDataControllerFilterChanged(Sender: TObject); var

Filter: TcxDataFilterCriteria; begin

with Sender as TcxDataFilterCriteria do if IsEmpty then

DataController.FocusedRowIndex := 0; end;

**************************************************************************** 52 排序后移到第一行 解决:

可以设置DataController.Options.FocusTopRowAfterSorting := True,也可以使用如下的代码: uses

cxCustomData;

百度搜索“70edu”或“70教育网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,70教育网,提供经典综合文库delphi控件cxGrid用法大全(5)在线全文阅读。

delphi控件cxGrid用法大全(5).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.70edu.com/wenku/460570.html(转载请注明文章来源)
Copyright © 2020-2025 70教育网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:370150219 邮箱:370150219@qq.com
苏ICP备16052595号-17
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:7 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219