Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2003, 06:08 AM
Joe Joe is offline
Senior Member
 
Join Date: Jul 2001
Posts: 130
Default DBGrid and Enter key

Hi,

I have a TTable, and one of the columns is a "lookup" field. In a TDBGrid,

1) how can i use the Enter key instead of the right and left arow to move to the next column?

2) when i enter the "lookup" field how can i make the dropdown list to be open so i can select from it?

Please any help with these two questions is a big help

Thank you
Reply With Quote
  #2  
Old 11-10-2003, 02:54 PM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: DBGrid and Enter key

Hi :-)

Q1) how can i use the Enter key instead of the right and left arow to move to the next column?

A1) You would intercept the arrow keys being pressed on the OnKeyDown event of the DBGrid and set the DBGrid's SelectedIndex property. This example bellow shows how to turn the enter keypress into a tab

if Key=VK_RETURN then
begin
Key := #0;

if DBGrid1.SelectedIndex < (DBGrid1.FieldCount-1)
DBGrid1.SelectedIndex := DBGrid1.SelectedIndex+1
else
DBGrid1.SelectedIndex := 0;

end;




Q2) when i enter the "lookup" field how can i make the dropdown list to be open so i can select from it?

A2) On the OnColumnEnter event for the DBGrid please try,

if DBGrid1.SelectedField.FieldName = 'Lookup Field Name' then
begin
//put the dbgrid into edit mode
DBGrid1.EditorMode := True;
//simulate the alt+down keys being pressed
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);
keybd_event(VK_DOWN, MapVirtualKey(VK_DOWN, 0), 0, 0);
keybd_event(VK_DOWN, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);

end;

If the user want's to close the list, the escape key would be needed to be pressed twice. Once to close the list and the second to lose it's focus.
Reply With Quote
  #3  
Old 11-10-2003, 07:44 PM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: DBGrid and Enter key

just a small typo ,

this

if Key=VK_RETURN then
begin
Key := #0;

should be

if Key=VK_RETURN then
begin
Key := 0;
Reply With Quote
  #4  
Old 11-11-2003, 08:09 AM
Joe Joe is offline
Senior Member
 
Join Date: Jul 2001
Posts: 130
Default Lookup field in a DBGrid using the Enter key

This is perfect and thank you so much, but i can not get the second part as you know I have a TTable, and one of the columns is a "lookup" field. In a TDBGrid,

How can i make the dropdown list of a lookup field to be open using the Enter key so i can select from it?
Reply With Quote
  #5  
Old 11-25-2003, 04:32 PM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: Lookup field in a DBGrid using the Enter key

Hi Joe.

Sorry for the late reply. I hope you got it working the way you wanted?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:34 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.