Delphi CxGrid 汇总(3)
列
解决:
<aColumn>.GroupIndex := -1;
<aColumn>.Visible := True;
****************************************************************************
39 保存修改到数据库
解决:
procedure <aForm>.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if (<aGrid>.FocusedView <> nil)
and (<aGrid>.FocusedView.DataController.EditState <> []) then
<aGrid>.FocusedView.DataController.Post;
end;
****************************************************************************
40 设置内置右键菜单
解决:
内置右键菜单包括二个菜单: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;
****************************************************************************
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
<GridView>.DataController.DataModeController.GridMode then
AllowPopup := False;
end;
****************************************************************************
43 主从表任何时候只能展开一个组
解决:
- procedure TForm1.ADetailDataControllerCollapsin( 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;
Delphi CxGrid 汇总(3)的更多相关文章
- Delphi CxGrid 汇总(4)
1. CxGrid汇总功能 ① OptionsView-Footer设置为True,显示页脚 ② CxGrid的Summary选项卡定义要汇总的列和字段名及汇总方式,Footer选项卡定义 ...
- Delphi CxGrid 汇总(2)
17. 怎样设计多表头的cxGrid? 解决:cxGrid可以解决如下的表头: --------------------------------- | 说明1 | 说明2 | ------------ ...
- delphi cxgrid 使用方法
delphi cxgrid 使用方法1.绑定数据 方法 cxGrid1DBTableView1.DataController.DataSource:=DataSource12.去掉"Drag ...
- 关于Delphi cxGrid主从表中从表只能编辑第一条记录的问题
在Delphi cxGrid主从表中从表只能编辑第一条记录,这个问题是由于设置主从关联字段错误造成的. 从表DBtableView2的keyfieldnames,DetailKeyFieldNames ...
- Delphi cxGrid使用汇总(一)
1. 去掉cxGrid中台头的Box解决:在tableview1的ptionsview的groupbybox=false; 2.统计功能解决:(1) tableview1. tableview1的op ...
- Delphi cxGrid –--> RecordIndex out of Range
delphi 导出数据时常常出现这样一个错误 < RecordIndex out of Range > 处理办法: 设定 cxGridDBTableView 的 GridModeBuffe ...
- Delphi - cxGrid颜色显示相关设置
1:单元格的值满足某个条件时,该单元格所在整行颜色设置整行字体设置 选中cxGridDBTableView,单击F11调出属性配置面板,在Events中双击OnCustomDrawCell后双击编辑重 ...
- Delphi - cxGrid内容xlsx、xls、csv格式导出
.xls格式导出,uses中添加cxGridExportLink 代码如下: function SaveToExcel(gridMain: TcxGrid; FileName: string): st ...
- Delphi - cxGrid设定合并单元格
在cxGrid中选中需要合并的字段,单击F11调出属性控制面板,展开Options,设置CellMerging的Value为True.
随机推荐
- JQuery基础教程:选择元素(下)
DOM遍历方法 利用前面介绍的jQuery选择符取得一组元素,就像是我们在DOM树中纵横遍历再经过筛选得到的结果一样.如果只有这一种取得元素的方式,那我们选择的余地从某个角度讲也是很有限的.很多情 ...
- 《Code Complete》ch.15 使用条件语句
WHAT? 条件语句指if.else.case.switch,循环语句指for.while WHY? 不用条件语句你写得出代码吗? HOW? if-then 正常情况放在异常情况之前 执行频率高的情况 ...
- 医失眠灵验方--五味子50g 茯神50g 合欢花15g 法半夏15g
方药:五味子50g 茯神50g 合欢花15g 法半夏15g 水煎服 主治:失眠健忘 此方为已故名老中医李培生之验方,用于临床治疗失眠健忘症,疗效显著,其主药为五味子,滋阴和阳,敛阳 ...
- 用Asroute解决复杂状态切换问题
项目地址:https://github.com/boycy815/asroute 首先明确几个概念 状态: 很多情况下,一个复杂的UI组件可能会有很多种不同的“状态”,不同的“状态”下组件本身对外界会 ...
- 发几个Flex的学习资源
书籍: 目前在看两本 <Essential.ActionScript.3.0> <Flex 4 In Action> 还有两本当手册翻阅,非常喜欢Cookbook这种题材的书, ...
- 缓存之Memcached
Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...
- mysql中explain看性能
select distinct col_name from table where a=X and b=Y and date(time)='xx-xx-xx';执行时间 27.9772 秒 expla ...
- CSS现代字体栈
CSS字体栈是一系列的字体,它包含了能在不同操作系统和平台上战士的字体,以尽可能的使排版保持一致性.浏览器会在font-family规定的所有字体中从前往后一次查找,如果找不到当前字体就查找下一个字体 ...
- 【MVC】ASP.NET MVC HtmlHelper用法大全
1.ActionLink <%=Html.ActionLink("这是一个连接", "Index", "Home")%> 带 ...
- 1.7见识一下什么叫Linux驱动:LED
1.任何的Linux驱动都有一个装载函数(装载驱动时调用)和一个卸载函数(卸载驱动时调用): 2.装载函数和卸载函数分别通过module_init和module_exit宏指定.