Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DBGrid - Set SelectedField. How?

0 views
Skip to first unread message

Lito Hernanz

unread,
Jun 27, 2002, 3:44:45 AM6/27/02
to
I am writing validation routines using the OnColExit event. The problem I am
trying to solve is: When the validation fails, the focus should return to
the cell just exited (or, better still, remain there). The closest thing I
could find in the documentation is to "Set SelectedField to move focus to a
particular field in the grid" --but it doesn't explain how to do it.

Any ideas will be much appreciated!

Lito Hernanz
Portland, Oregon


Constantine Yannakopoulos

unread,
Jun 27, 2002, 5:37:45 AM6/27/02
to

"Lito Hernanz" <litoh...@earthlink.net> wrote in message
news:3d1ac251_2@dnews...

> I am writing validation routines using the OnColExit event. The
problem I am
> trying to solve is: When the validation fails, the focus should
return to
> the cell just exited (or, better still, remain there). The closest
thing I
> could find in the documentation is to "Set SelectedField to move
focus to a
> particular field in the grid" --but it doesn't explain how to do it.

You should perform validations the OnValidate event of the underlying
datase's TField objects or in the dataset's BeforePost event. Putting
"business logic" code like validations in UI controls is always
considered bad practice.


Séb

unread,
Jun 27, 2002, 5:41:04 AM6/27/02
to
Hi,

Another way :
Look at TField.FocusControl...
I think it's what you're looking for....

Best regards...

Seb

PS :
Sorry for direct email... (twice)

"Lito Hernanz" <litoh...@earthlink.net> a écrit dans le message de news:
3d1ac251_2@dnews...

Quasidata

unread,
Jun 27, 2002, 12:03:01 PM6/27/02
to
Here is a sample. Suppose you have created the OnValidate event handler
for persistent field MyDataSetMyFieldName.

procedure TForm1.MyDataSetMyFieldNameValidate(Sender: TField);
begin
DBGrid1.SelectedField := Sender;
end;

--
Andrei Fomine.
DbAltGrid - multi-line layout, RTF and graphics of any kind in DBGrid.
Transfer@once - full-blown clipboard and drag-and-drop transfer in native
MS Office formats to/from any control.
www.quasidata.com


"Lito Hernanz" <litoh...@earthlink.net> wrote in message
news:3d1ac251_2@dnews...

Lito Hernanz

unread,
Jun 27, 2002, 4:31:18 PM6/27/02
to
I tried the procedure you suggested, and it makes Delphi crash with a Stack
Overflow. Any other ideas?

Lito

"Quasidata" <quasidataATquasidataDOTcom> wrote in message
news:3d1b3753$1_2@dnews...

Lito Hernanz

unread,
Jun 28, 2002, 12:04:06 AM6/28/02
to
Please disregard my other note. It works OK.
The stack overflow was actually happening in the adjacent cell, where I did
not have proper code in place. It was caused by a recursive call. I found it
unnecessary to "return to sender," because the exception handler
automatically puts me back where I wanted to be.

Thank you very much for coming to my rescue!!

Lito Hernanz


"Quasidata" <quasidataATquasidataDOTcom> wrote in message
news:3d1b3753$1_2@dnews...

Constantine Yannakopoulos

unread,
Jun 27, 2002, 5:37:45 AM6/27/02
to

"Lito Hernanz" <litoh...@earthlink.net> wrote in message
news:3d1ac251_2@dnews...
> I am writing validation routines using the OnColExit event. The
problem I am
> trying to solve is: When the validation fails, the focus should
return to
> the cell just exited (or, better still, remain there). The closest
thing I
> could find in the documentation is to "Set SelectedField to move
focus to a
> particular field in the grid" --but it doesn't explain how to do it.

You should perform validations the OnValidate event of the underlying

Séb

unread,
Jun 27, 2002, 5:41:04 AM6/27/02
to
Hi,

Another way :
Look at TField.FocusControl...
I think it's what you're looking for....

Best regards...

Seb

PS :
Sorry for direct email... (twice)

"Lito Hernanz" <litoh...@earthlink.net> a écrit dans le message de news:
3d1ac251_2@dnews...

Quasidata

unread,
Jun 27, 2002, 12:03:01 PM6/27/02
to
Here is a sample. Suppose you have created the OnValidate event handler
for persistent field MyDataSetMyFieldName.

procedure TForm1.MyDataSetMyFieldNameValidate(Sender: TField);
begin
DBGrid1.SelectedField := Sender;
end;

--
Andrei Fomine.
DbAltGrid - multi-line layout, RTF and graphics of any kind in DBGrid.
Transfer@once - full-blown clipboard and drag-and-drop transfer in native
MS Office formats to/from any control.
www.quasidata.com

"Lito Hernanz" <litoh...@earthlink.net> wrote in message
news:3d1ac251_2@dnews...

Lito Hernanz

unread,
Jun 27, 2002, 4:31:18 PM6/27/02
to
I tried the procedure you suggested, and it makes Delphi crash with a Stack
Overflow. Any other ideas?

Lito

"Quasidata" <quasidataATquasidataDOTcom> wrote in message
news:3d1b3753$1_2@dnews...

Lito Hernanz

unread,
Jun 28, 2002, 12:04:06 AM6/28/02
to
Please disregard my other note. It works OK.
The stack overflow was actually happening in the adjacent cell, where I did
not have proper code in place. It was caused by a recursive call. I found it
unnecessary to "return to sender," because the exception handler
automatically puts me back where I wanted to be.

Thank you very much for coming to my rescue!!

Lito Hernanz


"Quasidata" <quasidataATquasidataDOTcom> wrote in message
news:3d1b3753$1_2@dnews...

0 new messages