ExportGrid4ToExcel(sFileName,cxGrid1,true,true )要一个Form 中有两个cxGrid ,想哪个cxGrid 是 ActiveControl 是就导 哪个cxGrid 。用 ExportGrid4ToExcel(sFileName,TcxGrid(self.ActiveControl.Name),true,true )
不行。TcxGrid(self.ActiveControl.Name) 是空的
不行。TcxGrid(self.ActiveControl.Name) 是空的
ExportGrid4ToExcel(sFileName,TcxGrid(self.ActiveControl),true,true )
ExportGrid4ToExcel(sFileName,cxGrid1,true,true ) else if cxGrid2.IsFocused then
ExportGrid4ToExcel(sFileName,cxGrid2,true,true )
ExportGrid4ToExcel(sFileName,cxGrid,true,true )
begin
SaveDialog1.Execute ;
sFileName:=SaveDialog1.FileName+'.xls' ;
TdxDBGrid(self.ActiveControl).SaveToXLS(sFileName,true);
end ;如'TdxDBGrid' 这是样作的
var i:integer;
begin
for i:=0 to ComponentCount-1 do
begin
Memo1.Lines.Add(Components[i].Name);
if Components[i] is TWinControl then
Memo1.Lines.Add('TWinControl---'+Components[i].Name);
end;end;cxGrid1
TWinControl---cxGrid1
cxGrid1DBTableView1
cxGrid1Level1
Button1
TWinControl---Button1
Memo1
TWinControl---Memo1
由于cxGrid1是个容器,不能获取真正的焦点(可能是它的一个子控件如TableView),但TableView不是一个TWinControl而ActiveControl是一个TWinControl类型
哪就是说,不能像dxgrid 哪样了,有无方法可实现呢
procedure THR_RSZB_F.E2Click(Sender: TObject);
begin
inherited;
if qry_all.IsEmpty then
begin
MessageBox(Handle,'數據不能為空!!!','數據導出...',MB_OK+ MB_ICONWARNING);
Exit;
end else
begin
if dlgSave1.Execute then
begin
ExportGridToExcel(dlgSave1.FileName,cxGrid1,True,True,False,'XLS');
MessageBox(Handle,'數據成功導出!!!','數據導出...',MB_OK+ MB_ICONWARNING);
end;
end;
end;
切换到哪里不就知道了嘛
begin
SaveDialog1.Execute ;
sFileName:=SaveDialog1.FileName+'.xls' ;
ExportGrid4ToExcel(sFileName,TcxGrid(self.ActiveControl.ClassName),true,true );
end当cxgrid 得到focust时,self.ActiveControl.ClassName='TcxGridSite' ,不是cxgrid ,
当cxgrid 得到focust时,showmessage(self.ActiveControl.name) 是空的.