来源
 
1.  去掉GroupBy栏
cxGrid1DBTableView1.OptionsView.GroupByBox:=False;
 
2.  在GRID footer 中加入sum(列)
cxGrid1DBTableView1.OptionsView.footer:=Ture;
然后在cxGRid1的customize中的summary 的footer.add需要合计的列kind= skSum(这个是设计的方法,以后会增加代码方法)
3.  去掉cxgrid 中的过滤下拉箭头选择
cxGrid1DBTableView1.OptionsCustomize.ColumnFiltering:=Fasle;
4.  设置分组的统计项
方法1
a.cxGrid1DBTableView1.OptionsView.GroupFooters:=gfAlwaysVisible;
b.並設置需要求和的列,在summary.default for Groups 下add加入需要合计的字段,
column下显示fieldname 为统计字段,format为格式,kind为统计方法,position 为位子:spfooter 在分组的下面,spgroup 在分组的上面;
方法2
或用cxGridPopupMenu1,在運行時可對任意數字類型列求和,方法是只需設置cxGridPopupMenu1的屬性Grid為cxGrid1DBTableView1的cxGrid
 
5.  cxGrid默认的数值格式带¥,怎么去掉?
   雙擊Cxgrid,選擇column改變類型 options.properties.Memo(貌似有个money,我觉得应该用这个), 在displayformat中进行设置
6.  在网格最后一行的最后一格回车自动增加一条记录,并跳到新记录的第一格
cxGrid1DBTableView1.OptionsBehavior.FocusFirsCellOnNewRecord与GoToNextCellOnEnter为True,
FocusCellOnCycle设为True
7.   网格中通过Tab跳转
设置cxGrid1DBTableView1.OptionsBehavior.FocusCellOnTab:=True
8.  设置是否能够在网格中编辑数据
cxGrid1DBTableView1.OptionsData.Appending:=True,
Deleting为True,Editing为True
9.  设置是否能选中网格
cxGrid1DBTableView1.OptionsSelection.CellSelect:=True
 
10.  设置是否能够反选,
cxGrid1DBTableView1.OptionsSelection.InsertSelect:=True
11.  设置行高
cxGridDBTableView1.OptionsView.DataRowHeight
12.  改变字体
  cxStyleRepository 双击它,在里面添加GridTableViewStyleSheetDevExpress
  然后改变Style标签里面的cxStyle的字体就可以控制cxGrid的字体了

13.  有图片和MEMO的例子
拖入一个cxGrid1,Table1,DataSource1。 Table1的DatabaseName设为DBDEMOS,TableName设为biolife.db,
Active设为True; DataSource1的DataSet设为Table1;

cxGrid1DBTableView1的DataController中的DataSource设为DataSource1;

右击cxGrid1DBTableView1选择Create All Columns;

双击cxGrid1,在弹出的窗口中找到cxGrid1DBTableView1Notes和cxGrid1DBTableView1Graphic,将它们的Properties属性设为BlobEdit;运行看看结果。再将cxGrid1DBTableView1Graphic的Properties属性设为Image,再将Properties下的Stretch设为True, 将cxGrid1DBTableView1->optionsview->CellAutoHeight 设为True,看看结果。

15.GroupPanel上面的英文[Drag a column header to group by that column]怎么可以改成中文?

重绘的方法。
    解决:最简单的方法是 TcxGridTableView.OnCustomDrawPartBackground ,也可用 OnCustomDrawGroupCell:
    procedure TForm1.cxGrid1DBTableView1CustomDrawPartBackground(
               Sender: TcxGridTableView; ACanvas: TcxCanvas;
              AViewInfo: TcxCustomGridCellViewInfo; var ADone: Boolean);
    begin
      AViewInfo.Text:='动态设置 GroupBox 的显示内容';
      ACanvas.FillRect(AViewInfo.Bounds);
    end;

16.  如何实现如下功能:
           +财务部
           +原材料仓库
           +成品库
           +冲压车间
           +软件开发部
    这个是部门的名称,点击加号就可以将本部门的人员情况显示出来。

(这个我在考勤里已经实现,也可以是1个表的分组显示)
    解决:其实这是一个主从表关系,
 (1):填好主表的keyfieldnames
 (2):填好从表的keyfieldnames 
 (3):填好从表的 detaikeyfieldNames与masterkeyfieldnames
 (4): 从表的数据源一定要按与主表关联的字段排序    注:其它地方设置了主从表结构那样就显示不出来,比如设置了从表的Table或者Query的mastersource和asterfield就会不能显示数据!如果是两个cxGrid的主从关系,这样设置就很OK了。

17.类似PageControl显示

解决:增加一个Level,将cxGrid1->RootLevelOptions->DetailTabsPosition设为dtpTop(这是设置tab页标签,显示在哪里,这里设置显示在顶端),然后相应的设置cxGrid1Level1,和cxGrid1Level2的Caption值。

18.如何设定左边几列,不能滚动? 
解决:使用DB Banded Table才可以实现,
         在cxGrid1DBBandedTableView里建立Band0,Band1
         Band0的Fixed=tfLeft
         Band1的Fixed=tfnone
         设置要锁定的字段的BandIndex=0,其它为1,就OK了。

19.怎样实现如EXCEL一样的,当前格=G14+G15+G16 这样的功能
解决:举一个简单的例子:

label1.Caption := cxGrid1DBTableView1.DataController.Values[2,3]+cxGrid1DBTableView2.DataController.Values[1, 1]+cxGrid1DBTableView3.DataController.Values[1, 1];
所以不同cxGrid1DBTableView中的数据都可以给当前格,这样就做到了EXCEL中的当前格=G14+G15+G16 类似的功能。

//我的方法,在OnGetDataText事件中,修改值,这里因为该列是计算列

procedure Ti_kq_balance_form.cxGrid2DBTableView1Column15GetDataText(
  Sender: TcxCustomGridTableItem; ARecordIndex: Integer;
  var AText: String);
begin
  inherited;

AText:=FloatToStrF(1.5*VarToFloat(cxGrid2DBTableView1.DataController.GetValue(ARecordIndex,9))+
                     VarToFloat(cxGrid2DBTableView1.DataController.GetValue(ARecordIndex,10))*2+
                     VarToFloat(cxGrid2DBTableView1.DataController.GetValue(ARecordIndex,11))*3,ffGeneral,10,2);
  if  AText='0' then
      AText:='';

end;

22.如何使满足条件的数据显示不同的颜色?

具体可参见我的blog

http://usenet506.blog.163.com/blog/static/1213318820111791326440/
解决:
var
    AYellowStyle: TcxStyle;

procedure TForm1.FormCreate(Sender: TObject);
begin
  //行颜色
  AYellowStyle := TcxStyle.Create(Self);
  AYellowStyle.Color := $0080FFFF;
  AYellowStyle.TextColor := clMaroon;
end;

procedure TForm1.cxGrid1DBBandedTableView1StylesGetContentStyle(
    Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
    AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
if ARecord.Values[cxGrid1DBBandedTableView1Lengthcm.Index] < 81 then
  AStyle := AYellowStyle;
end;

这里cxGrid1DBBandedTableView1Lengthcm.Index小于81时就显示黄色

23.如何从外边的TXT文件导入到cxGrid?
解决:    (应该有更简单的方法)

procedure CustomizeColumns;
procedure LoadData;

procedure TForm1.CustomizeColumns;
const
 cDistance = 1;
 cRadius = 5;
 cPeriod = 4;
 cPstring = 0;
var
 I: Integer;
begin
 DecimalSeparator := '.';
 with cxGrid1TableView2 do
 for I := 0 to ColumnCount - 1 do
   if I in [cDistance, cRadius] then
     Columns[I].DataBinding.ValueTypeClass := TcxIntegerValueType//1,5列为Integer
   else
     if I in [cPstring,cPeriod] then
         Columns[I].DataBinding.ValueTypeClass := TcxStringValueType//0,4列为String
     else
          Columns[I].DataBinding.ValueTypeClass := TcxFloatValueType;//其他为Float
end;

procedure TForm1.LoadData;
const
 AFileName = '资产负债表.txt';
 AHeaderLineCount = 2;

var
     ARecords, AValues: TStringList;
     I: Integer;

procedure InitRecord(const Str: string);
 var
   J: Integer;
   V: Variant;
 begin
   AValues.CommaText := Str;
   for J := 0 to AValues.Count - 1 do
    if AValues.Strings[J] <> '-' then
    begin
     V := AValues.Strings[J];
     if not VarIsNull(V) then
       cxGrid1TableView2.DataController.Values[I, J] := V;
    end;
 end;

begin
 if not FileExists(AFileName) then
   raise Exception.Create('Data file not found');

ARecords := TStringList.Create;
 AValues := TStringList.Create;

with ARecords do
 try
   LoadFromFile(AFileName);
   cxGrid1TableView2.BeginUpdate;
   cxGrid1TableView2.DataController.RecordCount := Count - AHeaderLineCount;
   for I := 0 to Count - (AHeaderLineCount + 1) do
     InitRecord(Strings[I + AHeaderLineCount]);
 finally
   cxGrid1TableView2.EndUpdate;
   ARecords.Free;
   AValues.Free;
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 CustomizeColumns;
 LoadData_Zcfz;
end;

24.如何改变列的颜色?
var
 AFirstColumnStyle: TcxStyle;

procedure TForm1.FormCreate(Sender: TObject);
begin
 //列颜色
 AFirstColumnStyle := TcxStyle.Create(Self);
 AFirstColumnStyle.Color := clAqua;
 AFirstColumnStyle.TextColor := clBlue;
 cxGrid1TableView1.Columns[1].Styles.Content := AFirstColumnStyle;
end;

25.Set as default的用法?
解决:

Set as default的用法是为了解决设置参数的方便而做的,比如:
连好数据库以后,更改cxGrid1DBBandedTableView1->OptionsCustomize-> ColumnFiltering 设为False。(这个设置可以将字段名的下拉单给去掉)更改cxGrid1DBBandedTableView1->OptionsView- >Navigator 设置为True。然后右击cxGrid1DBBandedTableView1,在弹出的菜单栏里面点击Set as default。
OK,下次你再产生一个新的cxGrid1DBBandedTableView1时这些设置和刚才的一样了。如果需要设置的参数很多的时候,这个Set as default很有用!
  
26.怎样使鼠标移动时,相应的单元里的文字变色?
解决:
var
     FTrackItem: TcxCustomGridTableItem;
     FTrackRec: TcxCustomGridRecord;

procedure TForm1.cxGrid1DBTableView1CustomDrawCell(
     Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
     AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
 if (AViewInfo.GridRecord = FTrackRec) and (AViewInfo.Item = FTrackItem) then
 begin
   ACanvas.Font.Color := clred;   //红色字体
   ACanvas.Font.Style := [fsUnderline];//带下划线
 end;
end;

procedure TForm1.cxGrid1DBTableView1MouseMove(Sender: TObject;
 Shift: TShiftState; X, Y: Integer);
var
 AHitTest: TcxCustomGridHitTest;
 ATrackItem: TcxCustomGridTableItem;
 ATrackRec: TcxCustomGridRecord;
begin
 ATrackItem := FTrackItem;
 ATrackRec := FTrackRec;

AHitTest := (Sender as TcxGridSite).GridView.ViewInfo.GetHitTest(X, Y);
 if AHitTest is TcxGridRecordCellHitTest then
 begin
   FTrackItem := TcxGridRecordCellHitTest(AHitTest).Item;
   FTrackRec := TcxGridRecordCellHitTest(AHitTest).GridRecord;
 end
 else
 begin
   FTrackItem := nil;
   FTrackRec := nil;
 end;

if (ATrackItem <> FTrackItem) or (ATrackRec <> FTrackRec) then
 begin
   // Invalidate old cell
   if ATrackRec <> nil then
     ATrackRec.Invalidate(ATrackItem);
   // Invalidate new cell
   if FTrackRec <> nil then
     FTrackRec.Invalidate(FTrackItem);
 end;
end;

27.怎样设计多表头的cxGrid?
  解决:cxGrid可以解决如下的表头:
                   ---------------------------------
                   |     说明1     |     说明2     |
                   ---------------------------------
                   | 字段1 | 字段2 | 字段3 | 字段4 |
                   |      字段5    |     字段6     |
                   |      字段7    | 字段8 | 字段9 |
实现这个很简单,你可以直接在上面拖动字段名,拖动时会显示箭头的,放入你想显示的位置就OK了。或者在鼠标右击cxGrid1DBBandedTableView1菜单里的Edit Layout里也可以拖放。

28.在主从表结构时,当点开“+”时怎样将焦点聚在相应主表的记录上?
解决:
var
 HitTest: TcxCustomGridHitTest;

procedure TColumnsShareDemoMainForm.tvProjectsMouseDown(Sender: TObject;
 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 // Note that the Sender parameter is a Site
 HitTest := (Sender as TcxGridSite).GridView.ViewInfo.GetHitTest(X, Y);
 // The point belongs to the [+]/[-] button area
 if HitTest is TcxGridExpandButtonHitTest then
   // Move focus to the record
   TcxGridExpandButtonHitTest(HitTest).GridRecord.Focused := True;
end;

29.CXGrid4如何展开全部节点
 解决:GridDBTableView1.DataController.Groups.FullExpand;

30.cxGrid如何动态创建Items的Editor的项?
   cxGrid的列有一个属性,它的编辑框可以指定combobox,spinedit等.在设计时,可以为
   combobox的items添加项目.请问是否可以动态创建?(run-time时由程序加入)

解决:
 var
   A:TDataSource:
   B:TcxlookupcomboboxProperties;
 begin
   A:=TDataSource.create(self);
   B:=tcxlookupcomboboxproperties.create(self);
   A.Dataset:=Dic_ry_xb; //此处指定数据源。
   b.listdource:=a; //此处指明字段的listsource属性。
   b.keyfieldnames:='a';    //此处指明字段的关键字段
   b.listfieldnames:='b';   //此处指明字段的返回值。
   b.listcolumns.items[0].caption:='x;                              //此处默认是会建立一个字段,但是显示的表头是name,所以此处让它显示为自己想要的中午显示。
   cxGrid1DBTableView1c1_sex_code.Properties:=b;  //此处指明是那个字段。
end;  //这个是初始化的代码

31.获得当前行
   cgBrowseView.DataController.GetSelectionAnchorRowIndex

32.分组
  设置DBTableView的OptionCustomize->ColumnGrouping为True
  并设置要分组的字段的GroupIndex为一大于等于0的值

33.TdxDBTreeView的节点移动排序
利用TdxDBTreeView控件(此处设为DBTreeMain)时,可以从表中直接显示出树结构,有时需要拖动对节点进行排序,而且数据表中有字段SortCode用于排序码,此时需要编写对应代码,步骤如下
(1).先设置DBTreeMain的DragMode属性为dmAutomatic
(2).设置DBTreeMain的StateIndexField属性为SortCode
(3).在其OnEndDragTreeNode事件中写入
var
  m: TNodeAttachMode;
  oldOption: TdxDBTreeViewOptions;
  node: TdxDBTreeNode;
  bm: TBookmarkStr;
  idx: Integer;
begin
  inherited;
  try
    frmDragOption := TfrmDragOption.Create(nil);
    if frmDragOption.ShowModal = mrOK then
    begin
      //ShowMessage('1');
      if frmDragOption.rgOption.ItemIndex = 0 then
        m := naInsert
      else
        m := naAddChild;
      AttachMode := m;
      with DBTreeMain do
      begin
        oldOption := Options;
        Options := Options - [trCanDBNavigate];
        OnCompare := nil;
        bm := qryTree.Bookmark;
        qryTree.DisableControls;
        Items.BeginUpdate;
        try
          if m = naInsert then
          begin
            node := TdxDBTreeNode(Destination);
            idx := node.ImageIndex;
            UpdateSortCode(Source, idx);
            while node <> nil do
            begin
              Inc(idx, 10);
              UpdateSortCode(node, idx);
              node := TdxDBTreeNode(node.getNextSibling);
              if node = Source then
                Break;
            end;
          end
          else //添加子
          begin
            idx := GetChildMaxIdx(Destination) + 10;
            UpdateSortCode(Source, idx);
          end;
        finally
          Items.EndUpdate;
          Options := oldOption;
          OnCompare := DBTreeMainCompare;
          qryTree.EnableControls;
          qryTree.Bookmark := bm;
        end;
      end;
    end
    else
      //
  finally
    frmDragOption.Free;
  end;
end;

//UpdateSortCode过程
procedure TfrmSetTree.UpdateSortCode(ANode: TTreeNode; ASortCode: Integer);
var
  key: Variant;
begin
  key := TdxDBTreeNode(ANode).KeyFieldValue;
  with qryTree do
  begin
    if Locate('ID', key, []) then
    begin
      Edit;
      FieldByName('SortCode').AsInteger := ASortCode;
      Post;
    end;
  end;
  ANode.ImageIndex := ASortCode;
end;

//GetChildMaxIdx过程
function TfrmSetTree.GetChildMaxIdx(ANode: TTreeNode): Integer;
var
  i: Integer;
begin
  Result := 0;
  for i := 0 to ANode.Count - 1 do
  begin
    if ANode[i].ImageIndex > Result then
      Result := ANode[i].ImageIndex;
  end;
end;

(4).在其OnCompare事件中写入
procedure TfrmSetTree.DBTreeMainCompare(Sender: TObject; Node1,
  Node2: TTreeNode; Data: Integer; var Compare: Integer);
begin
  inherited;
  if Node1.ImageIndex > Node2.ImageIndex then
    Compare := 1
  else if Node1.ImageIndex = Node2.ImageIndex then
    Compare := 0
  else
    Compare := -1;
end;

34.在TdxDBTreeView控件的OnEditing事件中写入    ???
AllowEdit := CheckEdit;  //CheckEdit为判断的函数

35.选择某一行
cxgrdimport.SetFocus;
DBTVimport.ViewData.Records[0].Selected;

36.cxgrid单击某一网格事件,可在ViewTable的KeyPress事件中判断
if Key = #32 then
begin
  if Trim(colname.EditValue) = '' then
    colcode.FocusWithSelection
  //else
  //  colReqNum.Editing := True;
end;

37.动态生成列
  procedure CreateDynamicCols;
  var
    i, B_index: Integer;
  begin
    with BTVgather.Bands.Add do
    begin
      Caption := lcb1.Text;
      Position.ColIndex := 2;
    end;

for i := 4 to dsgather.DataSet.FieldCount - 1 do
    begin
      with BTVgather.Bands.Add do
      begin
        Position.BandIndex := 2;
        B_index := Index;
        Caption := dsgather.DataSet.Fields[i].FieldName;
        with BTVgather.CreateColumn do
        begin
          Position.BandIndex := B_index;
          Caption := dsgather.DataSet.Fields[i].FieldName;
          DataBinding.FieldName := dsgather.DataSet.Fields[i].FieldName;
          PropertiesClassName := 'TcxCurrencyEditProperties';
          TcxCurrencyEditProperties(Properties).DisplayFormat := ',0.00;-,0.00';
          Width := 80;
          OnGetDisplayText := Self.OnGetDisplayText;
        end;
      end;
    end;
    if BTVgather.Bands[2].ChildBandCount = 1 then
      BTVgather.Bands[2].Width := 90
    else
      BTVgather.Bands[2].Width := BTVgather.Bands[2].ChildBandCount * 90;
  end;

38.如何判断cxgrid单击了哪一列
procedure TFormModel.cxGrid1DBTableView1CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  ShowMessage(ACellViewInfo.Item.Caption);
  
  //s :=ACellViewInfo.GridRecord.Values[ACellViewInfo.Item.Index];
  //showmessage(s);
end;

39.改变CheckBox后直接提交(在PropertiesEditValueChanged中实现)

首先要设置此字段的options->Editing为True,然后写入代码(假设此字段为ViewDataColumn11):
procedure TfrmMain.ViewDataColumn11PropertiesEditValueChanged(
  Sender: TObject);
var
  RecMark:string;
begin
  inherited;
  ViewData.NavigatorButtons.Post.Click;
  if (FBiz.QryData1.FieldByName('PrintFlag').AsInteger=0) and
    (FBiz.QryData1.FieldByName('BillNo').AsInteger=0) then
  begin
    RecMark :=FBiz.QryData1.Bookmark;
    FBiz.QryData1.DisableControls;
    ExecQuery(qryRemote1,'update main set PrintFlag=0 where type='+FBiz.QryData1.FieldByName('Type').AsString);
    ShowQuery(FBiz.QryData1,'select * from Main order by Type,Code,BillNo');
    FBiz.QryData1.EnableControls;
    FBiz.QryData1.Bookmark :=RecMark;
  end;
end;

40.根据数据改变行的颜色

procedure TfrmMain.ViewDataStylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
  inherited;
  if (ARecord.Values[ViewDataColumn2.Index]=0) and
    (ARecord.Values[ViewDataColumn3.Index]=999999) then
    AStyle :=cxStyle4;
end;

我写的程序的例子

AYellowStyle: TcxStyle;

procedure TFrm_SettleDataOut.FormCreate(Sender: TObject);
begin
  //行颜色
 AYellowStyle := TcxStyle.Create(Self);
 AYellowStyle.Color := $0080FFFF;
 AYellowStyle.TextColor := clMaroon;
end;

procedure TFrm_SettleDataOut.cxGrid1DBTableView1StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
  //定义行的样式
  if (ARecord<>nil) and (ARecord.ValueCount>=24) and (ARecord.DisplayTexts[24]='1') then
    AStyle:=AYellowStyle;

//单独定义单元格的样式   只定义第24列的样式
  if (AItem<>nil) and (AItem.ID=24) and (ARecord.DisplayTexts[24]='1') then
     AStyle:=AYellowStyle;
end;

41.动态生成汇总列

procedure TfrmMain.CreateDynamicCols;
var
  csgItem: TcxDataSummaryItem;
  i: Integer;
begin
{$IFDEF Test}codesite.SendMsg('1'); {$ENDIF}
  btv2.DataController.Summary.FooterSummaryItems.Clear;
  for i := 0 to dsview2.DataSet.FieldCount - 1 do
  begin
    btv2.DataController.Summary.BeginUpdate;

with btv2.CreateColumn do
    begin
      Caption := dsview2.DataSet.Fields[i].FieldName;
{$IFDEF Test}codesite.SendMsg(Caption); {$ENDIF}
      DataBinding.FieldName := dsview2.DataSet.Fields[i].FieldName;
      HeaderAlignmentHorz := taCenter;

if i > 0 then
      begin
        PropertiesClassName := 'TcxCurrencyEditProperties';
        if (i mod 2) = 0 then
        begin
          TcxCurrencyEditProperties(Properties).DisplayFormat := ',0.00;-,0.00';
          csgItem := btv2.DataController.Summary.FooterSummaryItems.Add;
          csgItem.ItemLink := BTV2.Columns[i];
          csgItem.Kind := skSum;
          csgItem.Position := spFooter;
        end
        else
          TcxCurrencyEditProperties(Properties).DisplayFormat := ',0;-,0';
      end;
{$IFDEF Test}codesite.SendMsg('2'); {$ENDIF}
      if i > 1 then
        Position.BandIndex := 1;
      if i = 0 then
        Width := 78
      else
        if i = 1 then
          Width := 96
        else
          Width := 84;
    end;
{$IFDEF Test}codesite.SendMsg('3'); {$ENDIF}
    BTV2.Bands[0].Width := 78 + 96;
    BTV2.Bands[1].Width := BTV2.Bands[1].ChildBandCount * 84;
    btv2.DataController.Summary.EndUpdate;
  end;
end;

转自 http://bzdjc.blogbus.com/logs/32340883.html

1.简单介绍:cxGrid右下方的cxGrid1Level1是表示Grid表的层,cxGrid可以有多层,这相当于集合了PageControl的

功能, 而cxGrid1Level1右边的cxGrid1DBTableView1相当于DBGrid一样。右击cxGrid1可以添加cxGrid1Level2,右击

cxGrid1Level2,可以选择Create View , Add level 或者Delete Level。Add level可以增加子Level,Create View

里面可以选择很多不同总类的View。其中
1)DB Table可以和数据库连接的View,更一般的DBGrid类似,它比DBGrid多了比如鼠标中键可以用,可以统计,

查询,等等功能;
2)DB Banded Table 则可以实现比如:
---------------------------------
| 说明1 | 说明2 |
---------------------------------
| 字段1 | 字段2 | 字段3 | 字段4 |
等类似的功能;
3)DB Card View 则提供了卡片方式的显示数据的功能,这个用在比如人事档案管理比较不错;

cxgrid (数据库控件)控件的使用

http://bzdjc.blogbus.com/logs/32340635.html

2:一般用来查阅表信息,如果要修改的话,直接在上面编辑或添加非常不方便     
通常要放几个EDit来对选中的记录进行编辑或添加记录。
因为表一般都有主键,而用cxgrid很难控制。在post之前的主键检查工作。
3:由于没有直接进行编辑,而post之前又要进行主键检查工作(需要循环     
adoquery,此时的记录索引已经改变了)。所以我们要用一个bookmack。在编辑
的时候先Getbookmack,在确认修改数据的时候,先GotoBookMark,再把值更新。
4:在选择某条记录后,需要得到相应的字段值显示在Edit上面,这个时候就要用     
cxGridDBTableView的Cellclick事件里面处理;
可以用click事件里面的一个参数:ACellViewInfo。该参数的一个属性;
如:EdtMperson.text := ACellViewInfo.GridRecord.Values[2];
5:当需要得到随机选择的多条记录时有两种办法    
qrymast是一个adoquery
⑴第一步得到选择的总数
Icount := cxGrid1DBTableView1.DataController.GetSelectedCount;
⑵循环所有所选择的记录
for n := 0 to icount-1 do begin
⑶将选择记录的索引转换为数据集的索引
i := cxGrid1DBTableView1.DataController.GetSelectedRowIndex(n);
如果cxgriddbtableview没有设置排序,那么第一种方法也是正确的(因为cxgriddbtableview显示
的数据和qrymast显示的数据顺序是一样的)
//这是第一种方法,取qrymast的数据
inc(i);
//因为qrymast的记录是从1开始的
qryMast.RecNo := i;
得到需要的数据值
listbox1.Items.Add(qrymast.fields[0].asstring);
//这是第二种方法,取cxGrid1DBTableView1.ViewData的数据
if i =0 then
cxGrid1DB.DataController.GotoFirst
else
cxGrid1DBTableView1.DataController.RecNo := i;
str := cxGrid1DBTableView1.ViewData.Rows[i].Values[0];
listbox1.Items.Add(str);
end;
(一次测试的时候,cxGrid1DBTableView1.DataController.RecNo := 0;语句会报错,如果改为cxGrid1DB.DataController.GotoFirst,就没有问题)
6: 当有时候用到ACellViewInfo.GridRecord.Values[2]时候,由于values[2]是一个变体     
类型Variant,而如果这个时候相应的字段值如果为空,下面这样用就会报错。
EdtMperson.text := ACellViewInfo.GridRecord.Values[2]; 可以先判断一下:
if ACellViewInfo.GridRecord.Values[4]<>null then
MemRdesc.Lines.Text := ACellViewInfo.GridRecord.Values[4];

cxGrid的使用方法的更多相关文章

  1. ExpressQuantumGrid4的cxGrid的一些使用方法和经验

    使用cxGrid有一些时间了,在这里总结一下使用cxGrid的一些方法,希望给刚开始接触cxGrid的人一些帮助. 1.简单介绍:cxGrid右下方的cxGrid1Level1是表示Grid表的层,c ...

  2. cxgrid过滤使用心得

    uses cxFilter; cxgrid过滤条件清除:cxgrdbtblvwGrid1DBTableView2.DataController.Filter.AutoDataSetFilter:=Tr ...

  3. cxGrid 使用指南 1

    1:cxgrid是应该数据关联的控件,类似dbgrid.2:一般用来查阅表信息,如果要修改的话,直接在上面编辑或添加 非常不方便通常要放几个EDit来对选中的记录进行编辑或添加记录. 因为表一般都有主 ...

  4. javaSE27天复习总结

    JAVA学习总结    2 第一天    2 1:计算机概述(了解)    2 (1)计算机    2 (2)计算机硬件    2 (3)计算机软件    2 (4)软件开发(理解)    2 (5) ...

  5. delphi cxgrid 使用方法

    delphi cxgrid 使用方法1.绑定数据 方法 cxGrid1DBTableView1.DataController.DataSource:=DataSource12.去掉"Drag ...

  6. DevExpress - cxGrid 使用方法

    如何设置多选,并对多个选中行进行数据处理. 1.首先需要将需要获取的字段的列添加到 Grid 中,例如 grdDemoColumn1. 2.将 Grid 的 OptionsSelection 中的 C ...

  7. cxGrid增加一栏显示checkBox的设置方法

    鉴于本人首次设定cxGrid的CheckBox的时候费了很大劲,发现很多人都会碰到这个问题,现在总结一下,以供各位互相学习借鉴. 步骤如下(不分先后): 1. cxGrid添加完自己所需的所有字段后, ...

  8. CXGrid的使用技巧

    CXGrid的使用技巧 ========================================================================== 在主从TableView中 ...

  9. Delphi CxGrid 汇总(4)

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

随机推荐

  1. java中InvocationHandler 用于实现代理。

    以下的内容部分参考了网络上的内容,在此对原作者表示感谢! Java中动态代理的实现,关键就是这两个东西:Proxy.InvocationHandler,下面从InvocationHandler接口中的 ...

  2. Spring注入方式

  3. 由pthread_create引起的段错误

    一般线程的结束是由进程内的其他线程来结束的,调用pthread_cancel. 但是需要考虑到被结束线程的性质,一方面,线程是可被结束,也可无法结束,即不响应该信号:另一方面,如果线程是可被结束的,那 ...

  4. AlwaysOn可用性组测试环境安装与配置(一)--SQL群集环境搭建

    一.测试环境介绍 1. 宿主使用工作站(HYPR-V)基本配置如下: 处理器:Intel(R) Core(TM) i5-4470 CPU @ 3.20GHz 3.20GHz 内存(RAM):8.00G ...

  5. 【C语言入门教程】2.1 数据类型(5种基本数据类型),聚合类型与修饰符

    C语言有5种基本的数据类型,分别为 字符型.整型.单精度浮点型.双精度浮点型.空类型. 在不同的操作系统或硬件平台中,这些数据类型的值域范围和所占用的内存是有差异的.这种差异影响了C语言的可移植性能, ...

  6. C#第一次的Hello World

    这个Hello World是最基础的,在程序默认生成的using System下,不用自己可以的去写using System. 我们要牢记compling and running和running wi ...

  7. 错误:The Controls collection cannot be modified because the control contains code blocks (i.e. ). .

    用 <%# %>这种写法是写在数据绑定控件中的,之所以用 <%= %>会出现The Controls collection cannot be modified because ...

  8. php远程连接http方式

    以下这三者是通过GET方式来获取数据 1.socket 方式 一般是指定网址.端口号.超时时间. 再对报头进行修改以及传递参数,包括:header.method.content, 返回的内容包括hea ...

  9. python入门基础代码

    #查找index函数的帮助 help(str.index) #for循环和break语句from math import sqrtfor i in range(2,101): flag=1 k=int ...

  10. CentOS-6.5-saltstack-安装

    官方网站:https://www.saltstack.com/ 官方文档   https://docs.saltstack.cn/contents.html GitHub:  https://gith ...