使用easygrid1进行第一次录入,然后保存
使用easygrid2进行第二次录入
使用easygrid3读取第一次录入的数据怎样判断第二次录入和第一次录入的数据不同,如 If
EasyGrid2.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText <> EasyGrid3.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText
Then
begin
MessageBeep(0);
EasyGrid2.Colors[EasyGrid2.Col,EasyGrid2.Row]:=clred;
end;还有怎样限制录入字段的长度为3,只能输入数字和 ‘-’符号
使用easygrid2进行第二次录入
使用easygrid3读取第一次录入的数据怎样判断第二次录入和第一次录入的数据不同,如 If
EasyGrid2.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText <> EasyGrid3.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText
Then
begin
MessageBeep(0);
EasyGrid2.Colors[EasyGrid2.Col,EasyGrid2.Row]:=clred;
end;还有怎样限制录入字段的长度为3,只能输入数字和 ‘-’符号
if not (key in['0'..'9',#109]) then 报错限制录入字段的长度为3:
if length(EasyGrid2.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText)<>3 then 报错 ,在Uses中加入StrUtils至于判断第一次和第二次输入的不同,还是用一个全局变量来表示easygrid1中输入的数据吧。在EasyGrid1的保存事件中写入:
var
data1:string;在EasyGrid1的保存事件中写入:
data1:=EasyGrid1.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText;然后EasyGrid3读取时,比较EasyGrid2和data1变量的值,如果需要比较输入时间的先后,可以用两个Tdatatime型的变量,在EasyGrid保存时,分别记录两者的保存时间,通过时间对比就知道谁输入的次序先后了
然后在EasyGrid2里每输入一个单元格就判断一下和EasyGrid3里的是否一样,还有if not (key in['0'..'9',#109]) then 报错
if length(EasyGrid2.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText) <>3 then 报错
在哪里判断呢
procedure TForm1.EasyGrid1KeyPress(Sender: TObject; var Key: Char);
label
nexttab;
begin
if not (key in['0'..'9',#109,#32]) then
begin
key:=#0;
MessageBeep(0);
end;
if (key=#32) or (length(EasyGrid1.Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText) = 3) then
begin
key:=#0;
nexttab:
if (EasyGrid1.Col < EasyGrid1.ColCount - 1) then
begin
EasyGrid1.Col:=EasyGrid1.Col+1;
end
else
begin
if EasyGrid1.Row>=EasyGrid1.RowCount-1 then
EasyGrid1.RowCount:=EasyGrid1.rowCount+1;
EasyGrid1.Row:=EasyGrid1.Row+1;
EasyGrid1.Col:=0;
goto nexttab;
end;
end;
end;空格键能自动跳到下一单元格,但是数据长度为3时却没有反应
怎样让easygrid1的数据长度为3时自动跳到下一单元格呢
只是光标在输入框里时 用edit1.text := Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText显示不出来当前选择的单元格里的数据
不显示光标时,用edit1.text := Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText就可以显示出当前选择的单元格里的数据
begin
key:=#0; s:=0;
MessageBeep(0);
end else s:=1;最后给EasyGrid1添加一个onkeyup事件,把你所需的代码写在onkeyup事件中,如:procedure TForm1.StringGrid1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if s=1 then
begin
if length(EasyGrid1.Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText) = 3 then
edit1.Text:=EasyGrid1.Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText;
end;
end;你再试一下,我这边没有EasyGrid的控件,用stringgrid测试通过