如何获得DbGridEh正在处于编辑状态中的Cell值,请进... [高手]
如有一个Column正在编辑
当按下键盘后我需要知道该栏的值,但该值并没有post。
下面有短delphi的代码可以实现:
function GetDBGridEdit(mDBGrid: TDBGrid): TEdit;
var
I: Integer;
begin
Result := nil;
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 }
procedure TForm1.DBGrid1DblClick(Sender: TObject);
begin
Edit1.Text := GetDBGridEditText(DBGrid1);
end;
但是,我写成CB后,竟然不能捕获到ComponentCount,帮忙给看看!!翻译一下这个代码。
谢谢了
[解决办法]
翻译如下:
TEdit *GetDBGridEdit(TDBGrid *mDBGrid)
{
for(int i=0; i <mDBGrid-> ComponentCount; i++)
{
if(mDBGrid-> Components[i]-> InheritsFrom(__classid(TCustomEdit)))
return ((TEdit *)mDBGrid-> Components[i]);
}
return NULL;
}
String GetDBGridEditText(TDBGrid *mDBGrid)
{
TEdit *vEdit = GetDBGridEdit(mDBGrid);
if(vEdit)
return vEdit-> Text;
else
return " ";
}
void __fastcall TForm1::DBGrid1DblClick(TObject *Sender)
{
Edit1-> Text = GetDBGridEditText(DBGrid1);
}