Главная страница | назад





Article #16530: Selecting a cell in a DBGrid

 Question and Answer Database
FAQ1530D.txt Selecting a cell in a DBGrid
Category :VCL
Platform :All
Product :All 32 bit
Question:
How can I programmatically place a grid into edit mode and move the
cursor to a predetermined position in the edit box?
Answer:
Place the grid in editor mode, then get a handle to the edit box
and send a EM_SETSEL message, passing the initial position where you
want the cursor to appear, and the positon of the ending selection
(if you wish to highlight text).
The following example sets the cursor to the second character in the
edit control, and does not select any text.
Example:
procedure TForm1.Button1Click(Sender: TObject);
var
h : THandle;
begin
Application.ProcessMessages;
DbGrid1.SetFocus;
DbGrid1.EditorMode := true;
Application.ProcessMessages;
h := Windows.GetFocus;
SendMessage(h, EM_SETSEL, 2, 2);
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99