16,748
社区成员
发帖
与我相关
我的任务
分享
//清空
cxgInvoiceTableView.BeginUpdate();
for I := cxgInvoiceTableView.ItemCount - 1 downto 0 do
begin
if cxgInvoiceTableView.Items[I].Caption <> '选择' then
cxgInvoiceTableView.Items[I].Free;
end;
cxgInvoiceTableView.EndUpdate;
//重新创建
CreateGridColumn;
...
procedure DelColumns(ATV:TObject;AUnDelColumnCaption:string);
var
i,iBandindex,iColindex:integer;
btv:TcxGridBandedTableView;
dbtv:TcxGridDBBandedTableView;
begin
if ATV is TcxGridBandedTableView then
begin
btv:=TcxGridBandedTableView(ATV);
iColIndex:=-1;
iBandIndex:=-1;
for i:=0 to btv.ItemCount-1 do
if btv.Items[i].Caption=AUnDelColumnCaption then
begin
iColIndex:=i;
iBandIndex:=TcxGridBandedColumn(btv.Items[i]).Position.BandIndex;
break;
end;
for i:=btv.ItemCount-1 downto 0 do
if i<>iColIndex then btv.Items[i].Free;
for i:=btv.Bands.Count-1 downto 0 do
if i<>iBandIndex then btv.Bands[i].Destroy;
end
else if ATV is TcxGridDBBandedTableView then
begin
dbtv:=TcxGridDBBandedTableView(ATV);
iColIndex:=-1;
iBandIndex:=-1;
for i:=0 to btv.ItemCount-1 do
if dbtv.Items[i].Caption=AUnDelColumnCaption then
begin
iColIndex:=i;
iBandIndex:=TcxGridDBBandedColumn(dbtv.Items[i]).Position.BandIndex;
break;
end;
for i:=dbtv.ItemCount-1 downto 0 do
if i<>iColIndex then dbtv.Items[i].Free;
for i:=dbtv.Bands.Count-1 downto 0 do
if i<>iBandIndex then dbtv.Bands[i].Destroy;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
DelColumns(cxgInvoiceTableView,'选择');
showmessage(inttostr(cxgInvoiceTableView.ItemCount));
end;