• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

Retrieve text in dbgrid cell

I am using a Tdbgrid linked to a paradox table in Delphi3. How can I retrieve the new text that a user has typed in without leaving the control or posting to database.  I have tried dbGrid1.SelectedField.AsString and dbGrid1.SelectedField.Test but both do not give me the new text.  I have a function key setup to do a search after they  type in a few characters.
0
jfreisen
Asked:
jfreisen
  • 3
1 Solution
 
ZifNabCommented:
Hi jfreisen,

If you only want to recieve the entered text, try this :

procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 pressedkey := pressedkey + char(key);
 showmessage(pressedkey);
end;

0
 
ZifNabCommented:
Hi jfreisen,

If you only want to recieve the entered text, try this :

procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 pressedkey := pressedkey + char(key);
 showmessage(pressedkey);
end;

0
 
ZifNabCommented:
OnKeyPress maybe better event to handle this.
0
 
kretzschmarCommented:
hi jfreisen,

another method

//DBGrid Upkey-Event, can also be another event
procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var i : Integer;
begin
  for i := 0 to DBGrid1.ControlCount - 1 do
    if DBGrid1.Controls[i] is TInplaceEdit then
      edit1.text := TInplaceEdit(DBGrid1.Controls[i]).EditText;
end;

meikl
0
 
classmateCommented:
As far as i can remember from having the same problem one year ago, i tried to set the selected cell to the same one as the one already selected. Then the grid writes to the dataset, and the text can be read from the appropriate field (or at least i think so). The dataset can be canceled anyway.

I considered writing a inherited control from TDBGrid that solved the problem forever, but I've never been using DBGrids since :)

0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now