StringGrid 功能实现:StringGrid 中编辑完A列 回车就显示B列的值 (B列的值由公式:B=1/A得出) 这个如何实现呢
StringGrid 功能实现:StringGrid 中编辑完A列 回车就显示B列的值 (B列的值由公式:B=1/A得出) 这个怎么实现呢?
StringGrid 中编辑完A列 回车就显示B列的值 (B列的值由公式:B=1/A得出) 这个怎么实现呢?求大家帮忙,谢谢
------解决思路----------------------

------解决思路----------------------

在第一列的任意单元格内点击回车实现自动计算。
StringGrid 中编辑完A列 回车就显示B列的值 (B列的值由公式:B=1/A得出) 这个怎么实现呢?求大家帮忙,谢谢
------解决思路----------------------
var
Form1: TForm1;
C,R:Longint;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:='A';
StringGrid1.Cells[1,0]:='B';
StringGrid1.Cells[2,0]:='C';
end;
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
StringGrid1.MouseToCell(X,Y,C,R);
end;
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (C=0) and (R=1) then
begin
if Key=13 then
begin
if Trim(StringGrid1.Cells[0,1])='0' then
begin
ShowMessage('Error');
StringGrid1.Cells[1,1]:='';
end
else
if Trim(StringGrid1.Cells[0,1])<>'' then
StringGrid1.Cells[1,1]:=FloatToStr(1/StrToInt(StringGrid1.Cells[0,1]))
else
ShowMessage('Null');
end;
end;
end;
------解决思路----------------------
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
i:byte;
begin
for i:=1 to 4 do //假设有四行
begin
if (C=0) then //默认第一列
begin
if Key=13 then
begin
if Trim(StringGrid1.Cells[0,i])='0' then
begin
ShowMessage('Error');
StringGrid1.Cells[1,i]:='';
end
else
if Trim(StringGrid1.Cells[0,i])<>'' then
StringGrid1.Cells[1,i]:=FloatToStr(1/StrToInt(StringGrid1.Cells[0,i]))
else
ShowMessage('Null');
end;
end;
end;
end;
在第一列的任意单元格内点击回车实现自动计算。