去掉表头的拖列
设置tcxGridDBTableView的OptionView中的GroupByBox :=False;
设置某列不可编辑:
先设置列的Properties =TextEdit,再设置ReadOnly 为True, 为复选框时,类型为CheckBox,在onChange事件监听值的变化,代码如下,显示合计行在 tcxGridDBTableView中的OptionsView中设置Footer :=True,再设置 tcxGridDBColumn中Summary中设置footeFormat :=合计0条记录,FooterKind :=skCount 就可以显示数据集的记录数,其他类型设置FooterKind 这个即可,procedure Tfrm_cxGrid.EmpTableColumn4PropertiesChange(Sender: TObject);
begin
if Sender is TcxCheckBox then
begin
ShowMessage(IntToStr(Ord(TcxCheckBox(Sender).Checked)));
end;
// if TcxGridDBColumn(Sender).DataBinding.Field.AsBoolean=False then
// ShowMessage('TcxGridDBColumn(Sender).DataBinding为False');
end;
//多选
//获取多选行在表格中多选按Ctrl建
cxGrid2DBTableView1.OptionsSelection.MultiSelect :=True;
获取选中行的值
procedure TForm1.Button8Click(Sender: TObject);
var
i:Integer;
begin
for i := 0 to cxGrid2DBTableView1.Controller.SelectedRowCount-1 do
begin
cxGrid2DBTableView1.Controller.SelectedRows[i].Focused :=True;
ShowMessage('Current:'+DataSource1.DataSet.FieldByName('feecode').AsString);
end;
//清除选中行 EmpTable为tcxGridDBTableView
EmpTable.Controller.ClearSelection;
//cxGrid1DBBandedTableView1 点 Band操作 自写排序,实际还是应用了自身带的排序功能
在TcxGridBand(Sender) 的OnHeaderClick事件中增加如果代码,标题默认不允许为空,事件代码如下:
procedure TMain.cxGrid1DBBandedTableView1Bands0HeaderClick(Sender: TObject);
var
vFieldName:string;
vCaption:string;
begin
cxGrid1DBBandedTableView1.Controller.FocusedColumnIndex :=TcxGridBand(Sender).Columns[0].Index;
vFieldName :=cxGrid1DBBandedTableView1.Columns[cxGrid1DBBandedTableView1.Controller.FocusedColumnIndex].DataBinding.FieldName;
if cxGrid1DBBandedTableView1.Columns[cxGrid1DBBandedTableView1.Controller.FocusedColumnIndex].SortOrder =soNone then
begin
cxGrid1DBBandedTableView1.Columns[cxGrid1DBBandedTableView1.Controller.FocusedColumnIndex].SortOrder :=soAscending;
if Pos('↑',TcxGridBand(Sender).Caption)=0 then
TcxGridBand(Sender).Caption :=TcxGridBand(Sender).Caption+'↑';
end
else if cxGrid1DBBandedTableView1.Columns[cxGrid1DBBandedTableView1.Controller.FocusedColumnIndex].SortOrder =soAscending then
begin
cxGrid1DBBandedTableView1.Columns[cxGrid1DBBandedTableView1.Controller.FocusedColumnIndex].SortOrder :=soDescending;
if Pos('↑',TcxGridBand(Sender).Caption)>0 then
begin
vCaption :=TcxGridBand(Sender).Caption;
Delete(vCaption,Pos('↑',vCaption),1);
TcxGridBand(Sender).Caption :=vCaption+'↓';
end
end
else if cxGrid1DBBandedTableView1.Columns[cxGrid1DBBandedTableView1.Controller.FocusedColumnIndex].SortOrder =soDescending then
begin
cxGrid1DBBandedTableView1.Columns[cxGrid1DBBandedTableView1.Controller.FocusedColumnIndex].SortOrder :=soAscending;
if Pos('↓',TcxGridBand(Sender).Caption)>0 then
begin
vCaption :=TcxGridBand(Sender).Caption;
Delete(vCaption,Pos('↓',vCaption),1);
TcxGridBand(Sender).Caption :=vCaption+'↑';
end
end;
//排序
cxGrid1DBBandedTableView1.Columns[cxGrid1DBBandedTableView1.Controller.FocusedColumnIndex].SortIndex :=0;
end;
//自带的导出功能,也可用第三方xls导入控件 10.3版本自带的引用 cxGridExportLink 单元
if self.SaveDialog1.Execute then
ExportGridToExcel(self.SaveDialog1.FileName,cxGrid1,True,True,True,'xlsx');
//保存与恢复布局 FormCreate事件中恢复布局
IniFileName := ExtractFilePath(Application.ExeName) + 'Layout\' + Self.Name + '.ini';
if FileExists(IniFileName) then
Self.cxGrid1DBBandedTableView1.RestoreFromIniFile(IniFileName) //从布局文件中恢复
//保存布局 列宽信息 FormClose事件中加入
IniFileName := ExtractFilePath(Application.ExeName) + 'Layout\' + Self.Name + '.ini';
if not DirectoryExists(ExtractFileDir(IniFileName)) then
ForceDirectories(ExtractFileDir(IniFileName)); //(ExtractFileDir(IniFileName));
Self.cxGrid1DBBandedTableView1.StoreToIniFile(IniFileName); //保存为布局文件