PDA

View Full Version : حرکت بر روی فیلد های DBGrid توسط Enter



Mahdi_S_T
جمعه 20 آذر 1383, 20:44 عصر
چگونه با زدن اینتر بر روی فیلدهای DBGrid حرکت نماییم و هنگامی که از یک فیلد خارج میشویم . صحت اطلاعات آن چک شود ؟

http://tinypic.com/vl3ix

vcldeveloper
شنبه 21 آذر 1383, 02:18 صبح
برای استفاده از Enter بجای Tab می تونی از قطعه کد زیر استفاده کنی:


procedure TForm1.DBGrid1KeyPress (Sender: TObject; var Key: Char);
begin
If Key = #13 Then Begin
If HiWord(GetKeyState(VK_SHIFT)) <> 0 then begin
with (Sender as TDBGrid) do
if selectedindex > 0 then
selectedindex := selectedindex - 1
else begin
DataSource.DataSet.Prior;
selectedindex := fieldcount - 1;
end;
end else begin
with (Sender as TDBGrid) do
if selectedindex < (fieldcount - 1) then
selectedindex := selectedindex + 1
else begin
DataSource.DataSet.Next;
selectedindex := 0;
end;
end;
Key := #0
end;
end;

about.delphi.com


برای چک کردن صحت مقدار وارد شده در هر فیلد هم می تونی از رویداد OnColExit استفاده کنی.