?
Solved

TComboBox Enter as Tab behaviour

Posted on 2005-02-25
2
Medium Priority
?
367 Views
Last Modified: 2010-04-05
Hi,

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;

interface

uses
  Windows, SysUtils, Classes, Controls, StdCtrls;

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

implementation

uses
  Messages, Dialogs;

procedure TProM_ComboBox.KeyPress(var Key: Char);
begin
  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);
end;

end.
0
Comment
Question by:intercad
2 Comments
 
LVL 5

Accepted Solution

by:
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);
begin
  MessageDlg(IntToStr(Ord(Key)), mtInformation, [mbOK], 0);     // Debug
  if Key = Char(VK_RETURN) then
  begin
     SelectNext(Sender as TWinControl, true, true);
     Key:=#0;
  end;
  inherited KeyPress(key);
end;
0
 

Author Comment

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

Thanks a lot.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

621 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