cxGridCustomTableView cxGrid001 修改5492行 添加如下语句: ord('c'), ord('C'): begin if ssCtrl in Shift then Clipboard.AsText:=GetDisplayText(Controller.GetFocusedItemIndex); end; 使表格在只读模式下可以复制选定单元格的数据.
数据复制到剪切板,那直接操作剪切板不就行了? var cpb:TClipBoard; 然后调用cpb的方法
取不到当前cell的值,因为取不到当前是哪一列,只能取到当前是那一行
在 Form 的 OnKeyDown var SCT : TWinControl; Controller:TcxCustomGridTableController; begin //先看当前的焦点是什么 SCT := ActiveControl; while SCT <> nil do begin if(SCT.Name = '') then begin SCT := SCT.Parent; end else begin Break; end; end; if(ssCtrl in Shift) then begin if( Key = Ord('C')) then begin //Ctrl + C if( SCT is TcxGrid) then begin if ( TcxGrid(SCT).FocusedView.Controller is TcxCustomGridTableController ) then begin try Controller := TcxCustomGridTableController(TcxGrid(SCT).FocusedView.Controller); AStr := Controller.FocusedRecord.DisplayTexts[Controller.FocusedItem.Index]; Clipboard.AsText := AStr; except end; end; end; end; end;
如果不用,那么你在做复制的时候先把Editing改为True,添加了数据后改回来罗
cxGrid001 修改5492行
添加如下语句:
ord('c'), ord('C'):
begin
if ssCtrl in Shift then
Clipboard.AsText:=GetDisplayText(Controller.GetFocusedItemIndex);
end;
使表格在只读模式下可以复制选定单元格的数据.
var
cpb:TClipBoard;
然后调用cpb的方法
var
SCT : TWinControl;
Controller:TcxCustomGridTableController;
begin
//先看当前的焦点是什么
SCT := ActiveControl;
while SCT <> nil do
begin
if(SCT.Name = '') then
begin
SCT := SCT.Parent;
end else
begin
Break;
end;
end; if(ssCtrl in Shift) then
begin
if( Key = Ord('C')) then
begin
//Ctrl + C
if( SCT is TcxGrid) then
begin
if ( TcxGrid(SCT).FocusedView.Controller is TcxCustomGridTableController ) then
begin
try
Controller := TcxCustomGridTableController(TcxGrid(SCT).FocusedView.Controller);
AStr := Controller.FocusedRecord.DisplayTexts[Controller.FocusedItem.Index];
Clipboard.AsText := AStr;
except
end;
end;
end;
end;
end;