delphi cxgrid 使用方法

delphi cxgrid 使用方法
1.绑定数据
 方法
 cxGrid1DBTableView1.DataController.DataSource:=DataSource1
2.去掉"Drag   a   column   header   here   to   group   by   that   column"
方法
cxGrid1DBTableView1.OptionsView.GroupByBox置为False
3.去掉表头下三角数据 
方法
cxGrid1DBTableView1.Optionscustomize.columnfiltering置为False
4.增加序号
方法
在dataset 里边增加 Mycount 字段 类型为 string
在 CXgrid 增加显示字段 序号 mycount
为该字段写事件
procedure Tfrm_form.ReDataSet2mycountGetText(Sender: TField;
  var Text: String; DisplayText: Boolean);
begin
  inherited;
  text:=inttostr(redataset2.RecNo);
end;

将 序号 绑定 字段 Mycount

5.CXgrid 增加一栏显示checkBox
方法
在dataset 里边增加 MySelect字段 类型为 BOOLEAN 

在 CXgrid 增加显示字段 选择 select 

设定select 字段的Properties为 CheckBox .  ReadOnly = False;
NullStyle = nssUnchecked 

procedure Tfrm_form.cxGrid1DBTableView1CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var
  Row: Integer;
begin
  inherited;

  if ACellViewInfo.Item.Name = 'mycheck' then
  begin
    Row := cxGrid1DBTableView1.DataController.FocusedRecordIndex;
    if cxGrid1DBTableView1.ViewData.Records[Row].Values[0] = True then
      cxGrid1DBTableView1.ViewData.Records[Row].Values[0] := False
    else
      cxGrid1DBTableView1.ViewData.Records[Row].Values[0] := True;
  end;

end; 



procedure Tfrm_form.cxGrid1DBTableView1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Row: Integer;
begin
  inherited;
  //单选
  // for Row:=0 to  cxGrid1DBTableView1.DataController.RecordCount-1 do
  // begin
  //   cxGrid1DBTableView1.ViewData.Records[Row].Values[0] := False;
  // end;
  //多选
    if  cxGrid1DBTableView1.DataController.RecordCount<>0 then
  begin
   Row := cxGrid1DBTableView1.DataController.FocusedRecordIndex;

  if cxGrid1DB

原文地址:https://www.cnblogs.com/m0488/p/3833333.html