在ondrawcell里作判断吧
例如:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if TStringGrid(Sender).cells[ACol,ARow]<>'' then TStringGrid(Sender).cells[ACol,ARow]:='';
inherited;
end;
例如:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if TStringGrid(Sender).cells[ACol,ARow]<>'' then TStringGrid(Sender).cells[ACol,ARow]:='';
inherited;
end;
解决方案 »
- 谁给一个画圆的代码我?
- 如何用API函数关闭监视器
- 高手啊,,请帮我将这个C++原形转换成delphi的原形,谢谢拉
- 我想做个流动字幕,需要用什么控件
- 关于Web Services的问题
- rational rose 可不可以给delphi建模?我装了一个,好像不行。
- 怎样控制RichEdit的滚动条滑块的位置?
- 如何把图片复制到表格中
- TFont和TPicture的动态数组,如何能够保存到dfm中,并读出?
- csdn里已经解决的问题都跑哪里了??原来可是一万多条呢,现在怎么只有100条了?斑竹或者谁知道告诉一声,谢了
- CSDN查询助手v1.0 beta 1正式发布,查询速度快,浏览贴子速度更快
- 怎样控制并口的数据端口,我用来控制自制挂在并口上的东东
begin
if (stringgrid1.col=1) and not (key in ['0'..'9']) then
key:=char(0);
end;
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',#8]) then
key := #0;
end;
DrawString:string;
Sw,Sh,x,y:integer;
begin
DrawString:=Sg_TurnOver.Cells[acol,arow];
Sg_TurnOver.Canvas.FillRect(Rect);
Sw:=Sg_TurnOver.Canvas.TextWidth(DrawString);
Sh:=Sg_TurnOver.Canvas.TextHeight(DrawString);
if (Acol=1) and (Arow >0) then
begin
if drawstring='' then
Exit;
DrawString:=Formatcurr('#,##0.00',StrToCurr(Sg_TurnOver.Cells[ACol,ARow]));
Sg_TurnOver.Canvas.FillRect(Rect);
Sw:=Sg_TurnOver.Canvas.TextWidth(DrawString);
Sh:=Sg_TurnOver.Canvas.TextHeight(DrawString);
if (Sw > (rect.Right - rect.left)) then
begin
x:=4;
y:=(rect.Bottom - rect.top - Sh) div 2;
Sg_TurnOver.Canvas.TextOut(rect.left + x ,rect.top + y,Sg_TurnOver.Cells[ACol,ARow]);
end
else
begin
x:=(rect.Right - rect.left - sw) div 2;
y:= (rect.Bottom - rect.top - sh) div 2;
Sg_TurnOver.Canvas.TextOut(rect.right-sw-6,rect.top + y,Formatcurr('#,##0.00',StrToCurr(Sg_TurnOver.Cells[ACol,ARow]))); end;
end
else
begin
if (Sw > (rect.Right - rect.left)) then //只能左对齐
begin
x:=4;
y:=(rect.Bottom - rect.top - Sh) div 2;
Sg_TurnOver.Canvas.TextOut(rect.left + x ,rect.top + y,Sg_TurnOver.Cells[ACol,ARow]);
end
else
begin
x:=(rect.Right - rect.left - sw) div 2;
y:= (rect.Bottom - rect.top - sh) div 2;
Sg_TurnOver.Canvas.TextOut(rect.left + x ,rect.top + y,Sg_TurnOver.Cells[ACol,ARow]);
end;
end;
OnSelectCell中begin
if (Sg_TurnOver.Cells[acol,arow]='0') or (Sg_TurnOver.Cells[acol,arow]='') then
exit;
try
EndPrice := StrToCurr(Sg_TurnOver.Cells[acol,arow]);
except
MessageDlg('此栏['+Sg_TurnOver.Cells[0,Arow]+','+Sg_TurnOver.Cells[Acol,0]+']金额输入错误!',mtError,[mbOK],0);
exit;
end;
end;
还要在form中设置一个属性:keypreview 为True
if not (key in ['0'..'9',#13,#8]) then //#13回车;#8退格
key := chr(0);
你试看吧