TComboBox Enter as Tab behaviour

Posted on 2005-02-25
Medium Priority
Last Modified: 2010-04-05

I defined a new component derived from TComboBox  to automate de usage of the Enter key as Tab and other minor stuff. On TEdit control it worked all right. On TComboBox the event handler KeyPress is raised twice for each Enter key press, as a result one control is always jumped in the tab order list. I only tested with DropDownList style.

The application is quite big so I really want to go forward with the new class approach.

Tests I made so far:

Using Perform instead of PostMessage doesn't help.

BackSpace key works all right (is only processed once).

Using KeyUp instead of KeyPress as the same result but with a different behaviour. TComboBox seems to handle the Enter given to the previous control and jumps to the following control.

I really need some help here.

Thanks in advance for all the help.

Vieira da Silva

Here is the code skeleton, the register procedure is on another unit.

unit ProM_ComboBox;


  Windows, SysUtils, Classes, Controls, StdCtrls;

  TProM_ComboBox = class(TComboBox)
    { Protected declarations }
    procedure KeyPress(var Key: Char); override;


  Messages, Dialogs;

procedure TProM_ComboBox.KeyPress(var Key: Char);
  MessageDlg(IntToStr(Ord(Key)), mtInformation, [mbOK], 0);      // Debug
  if Key = Char(VK_RETURN) then
    if Owner is TWinControl then
      PostMessage((Owner as TWinControl).Handle, WM_NEXTDLGCTL, 0, 0);

  inherited KeyPress(key);

Question by:intercad
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

Greybird earned 800 total points
ID: 13401451
I would do something like that (not tested). I think setting Key to #0 should resolve your issue.

procedure TProM_ComboBox.KeyPress(Sender: TObject; var Key: Char);
  MessageDlg(IntToStr(Ord(Key)), mtInformation, [mbOK], 0);     // Debug
  if Key = Char(VK_RETURN) then
     SelectNext(Sender as TWinControl, true, true);
  inherited KeyPress(key);

Author Comment

ID: 13401527
I could I have missed that...

Thanks a lot.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question