32根据单元的值设置样式  
解决:
procedure   <aForm>.<aColumn>StylesGetContentStyle(  
      Sender:   TcxCustomGridTableView;   ARecord:   TcxCustomGridRecord;  
      AItem:   TcxCustomGridTableItem;   out   AStyle:   TcxStyle);  
begin  
      if   ARecord.Values[AItem.Index]   =   aSomeValue   then  
          AStyle   :=   <aSomeStyle>;  
end;  
   
procedure   <aForm>.<aView>StylesGetContentStyle(  
      Sender:   TcxCustomGridTableView;   ARecord:   TcxCustomGridRecord;  
      AItem:   TcxCustomGridTableItem;   out   AStyle:   TcxStyle);  
var  
      AColumn:   TcxCustomGridTableItem;  
begin  
      AColumn   :=   (Sender   as   TcxGridDBTableView).GetColumnByFieldName('Email');  
      if   VarToStr(ARecord.Values[AColumn.Index])   =   ''   then  
          AStyle   :=   cxStyleNullEmail;  
end;  
   
======================================================================
   
TcxCustomGridTableView.FindItemByName,   TcxGridDBTableView.GetColumnByFieldName   or  
TcxGridDBDataController.GetItemByFieldName  
   
      with   cxGrid1DBBandedTableView1.DataController   do  
          AValue   :=   Values[FocusedRecordIndex,   GetItemByFieldName('SomeFieldName').Index];  
   
****************************************************************************
33动态生成BandedView
解决:
var  
      AView:   TcxCustomGridView;  
begin  
      AView   :=   <cxGrid>.CreateView(TcxGridDBBandedTableView);  
      TcxGridDBBandedTableView(AView).DataController.DataSource   :=   <DataSource>;  
      TcxGridDBBandedTableView(AView).Bands.Add;  
      with   TcxGridDBBandedTableView(AView).Bands.Add   do  
      begin  
          Visible   :=   False;  
          FixedKind   :=   fkLeft;  
      end;  
      TcxGridDBBandedTableView(AView).DataController.CreateAllItems;  
      <cxGridLevel>.GridView   :=   AView;
end;
****************************************************************************
34当底层数据集为空时显示一条空记录
解决:
procedure   <Form>.<cxGrid>Enter(Sender:   TObject);  
var  
      View:   TcxGridDBTableView;  
begin  
      View   :=   TcxGridDBTableView((Sender   as   TcxGrid).FocusedView);  
      if   View.DataController.DataSet.IsEmpty   then  
      begin  
          View.DataController.DataSet.Append;  
          View.Controller.EditingController.ShowEdit;  
      end;  
end;
****************************************************************************
35 在当前View插入记录  
解决:
使用FocusedView属性得到当前焦点View,用View.DataController得到对应的Data   Controller,  
之后使用Data   Controller的方法来操作数据:  
-   Append  
-   Insert  
-   Post  
-   Cancel  
-   DeleteFocused  
-   DeleteSelection  
   
示例:  
var  
      ARecIndex:   Integer;  
…  
      View.DataController.Append;  
      ARecIndex   :=   View.DataController.FocusedRecordIndex;  
      View.DataController.Values[ARecIndex,   SomeItemIndex]   :=   SomeValue;  
      View.DataController.Post;  
   
另外一种方法是使用View.DataController.DataSource.DataSet得到底层数据集后,再用数据集的方法来操作数据。
****************************************************************************
36激活内置编辑控件
解决:
    1)   <aView>.Controller.EditingController.ShowEdit(<aColumn>);  
    2)   <aView>.Controller.EditingController.StartEditShowingTimer(<aColumn>);  
    3)   <aView>.Controller.EditingItem   :=   <aColumn>;  
    4)   <aColumn>.Editing   :=   True;
****************************************************************************
37隐藏内置编辑控件
解决:
<aView>.Controller.EditingController.HideEdit(True);
****************************************************************************
38 移除一个分组列  
解决:
      <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.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;
****************************************************************************

cxGrid使用汇总3的更多相关文章

  1. cxGrid使用汇总(一)

    1. 去掉cxGrid中台头的Box 解决:在tableview1的ptionsview的groupbybox=false; 2.统计功能 解决:(1) tableview 1. tableview1 ...

  2. cxGrid使用汇总2

    17. 怎样设计多表头的cxGrid? 解决:cxGrid可以解决如下的表头: --------------------------------- | 说明1 | 说明2 | ------------ ...

  3. cxGrid使用汇总1

    这些都不是原创,只是平时收集到资料然后整理的,有些可能百度一下到处都是而且还大同小异也有些不是很好找,现在贴出来希望给那些用到cxGrid的人会有所帮助 1. 去掉cxGrid中台头的Box 解决:在 ...

  4. Delphi cxGrid使用汇总(一)

    1. 去掉cxGrid中台头的Box解决:在tableview1的ptionsview的groupbybox=false; 2.统计功能解决:(1) tableview1. tableview1的op ...

  5. cxGrid使用汇总4

    1.     CxGrid汇总功能 ① OptionsView-Footer设置为True,显示页脚   ② CxGrid的Summary选项卡定义要汇总的列和字段名及汇总方式,Footer选项卡定义 ...

  6. cxGrid使用汇总

    1.自动行高:CellAutoHeight(单元自动高度)设置为True. procedure <AForm>.<AGridColumn>PropertiesValidate( ...

  7. 关于 cxGrid 的过滤问题

    http://bbs.csdn.net/topics/390536919 关于 cxGrid 的过滤问题 [问题点数:20分,结帖人zhengyc653]             不显示删除回复   ...

  8. Delphi CxGrid 汇总(4)

    1.     CxGrid汇总功能 ① OptionsView-Footer设置为True,显示页脚   ② CxGrid的Summary选项卡定义要汇总的列和字段名及汇总方式,Footer选项卡定义 ...

  9. Delphi CxGrid 汇总(2)

    17. 怎样设计多表头的cxGrid? 解决:cxGrid可以解决如下的表头: --------------------------------- | 说明1 | 说明2 | ------------ ...

随机推荐

  1. Which HTTP methods match up to which CRUD methods?

    https://stackoverflow.com/questions/6203231/which-http-methods-match-up-to-which-crud-methods   Crea ...

  2. 【转】和菜鸟一起学linux之DBUS基础学习记录

    [原文] D-Bus三层架构 D-Bus是一个为应用程序间通信的消息总线系统, 用于进程之间的通信.它是个3层架构的IPC 系统,包括: 1.函数库libdbus ,用于两个应用程序互相联系和交互消息 ...

  3. cn_03_r2_enterprise_sp2_x86_vl_X13_46432

    1. 使用的 ISO为:cn_win_srv_2003_r2_enterprise_with_sp2_vl_cd1_X13-46432.iso 2.序列号 用的序列号是“DF74D-TWR86-D3F ...

  4. Amazon SES介绍 - SES发送邮件的过程

     Amazon SES,  全称Amazon Simple Email Service,即Amazon简单邮件服务,它是Amazon提供的一款供开发人员或公司企业用来处理邮件相关业务的服务,也就是说, ...

  5. Angular表达式--插值字符串($interpolate)

    要在字符串模板中做插值操作,需要在你的对象中注入$interpolate服务.在下面的例子中,我们将会将它注入到一个控制器中: angular.module('myApp', []) .control ...

  6. appium自动化测试(一)

    一. appium的引入 二. adb adb(Android Debug Brige)是用来连接安卓手机和PC端的调试桥梁,通过adb服务,在PC端命令行界面对手机或者模拟器进行全面的操作 安装: ...

  7. python之单元测试框架—unittest(补充)

    一. unittest最核心的四个概念 unittest中最核心的四个概念是:test case,test suite,test runner,test fixture TestCase:一个test ...

  8. JsonUtils

    import net.sf.json.JSONObject; public class JsonTools { public static JSONObject getJSONObject(Strin ...

  9. shell基础复习笔记

    变量的设置 以等号连接,等号两边不能有空格 变量名首个字符必须是英文,可以使用下划线,不能使用标点符号,不能使用bash里的关键字 可以使用转义字符\将特殊符号(如Enter.$.空格.!等)变成一般 ...

  10. 三个大数据处理框架:Storm,Spark和Samza 介绍比较

    转自:http://www.open-open.com/lib/view/open1426065900123.html 许多分布式计算系统都可以实时或接近实时地处理大数据流.本文将对三种Apache框 ...