1. 程式人生 > >Delphi處理數據網格DBGrid的編輯框 獲取還沒有提交到數據集的字段文本

Delphi處理數據網格DBGrid的編輯框 獲取還沒有提交到數據集的字段文本

dshow rom tom ins 顏色 dsi with str pro

//from
http://kingron.myetang.com/zsfunc12.htm

(*//
標題:處理數據網格的編輯框
說明:示例添加焦點顏色;獲取還沒有提交到數據集的字段文本
設計:Zswang
日期:2002-03-31
支持:[email protected]
//*)

///////Begin Source
function GetDBGridEdit(mDBGrid: TDBGrid): TEdit;
var
I: Integer;
begin
Result := nil;
if not Assigned(mDBGrid) then Exit;
if not mDBGrid.EditorMode then begin

mDBGrid.EditorMode := True;
mDBGrid.EditorMode := False;
end;
with mDBGrid do for I := 0 to Pred(ComponentCount) do
if Components[I] is TCustomEdit then begin
Result := TEdit(Components[I]);
Break;
end;
end; { GetDBGridEdit }

function GetDBGridEditText(mDBGrid: TDBGrid): string;
var
vEdit: TEdit;
begin
vEdit := GetDBGridEdit(mDBGrid);
if Assigned(vEdit) then
Result := vEdit.Text
else Result := ‘ ‘;
end; { GetDBGridEditText }
///////End Source

///////Begin Demo
procedure TForm1.DBGrid1Enter(Sender: TObject);
var
vEdit: TEdit;
begin
vEdit := GetDBGridEdit(TDBGrid(Sender));
if Assigned(vEdit) then vEdit.Color := clYellow;
end;

procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Caption := GetDBGridEditText(TDBGrid(Sender));
end;
///////End Demo

procedure TForm4.dbgrdShowKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
with qry1 do //動態計算
begin
if (FindField(‘總價‘)<>nil) and (FindField(‘數量‘)<>nil) and (FindField(‘單價‘)<>nil) then
if State in [dsinsert,dsedit] then
begin
UpdateRecord;
FieldByName(‘總價‘).AsString:=StrOpt(DasS(qry1,‘數量‘),‘*‘,DasS(qry1,‘單價‘));
end;
end;

end;

Delphi處理數據網格DBGrid的編輯框 獲取還沒有提交到數據集的字段文本