When setting TComboBox.DroppedDown to true, how can I prevent the mouse cursor from disappearing?

186 Views Asked by At

In Delphi 2007 I'm attempting for force a TComboBox to drop down, however when I do, the mouse cursor disappears while the control is editing and the the mouse is over the form. I've come upon this idea after reading this SO answer on implementing a filter feature using a TComboBox.

To demonstrate the behavior.

  1. Run the sample code below (time machine might be needed to 2007)
  2. click in the combo box
  3. Start typing.

In the sample code you can see two workarounds I tried that did not prove fruitful.

Can the disappearing cursor be overcome?

An alternative free control/component that achieves the same goal of filtering a list while typing is welcomed as well. I need to filter items based on if they contain the text anywhere within the item, so the autocomplete route doesn't appear to be an option.

Cheers,

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure ComboChange(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBox1.AutoComplete := false;
  ComboBox1.Style := csDropDown;
  ComboBox1.OnChange := ComboChange;

  ComboBox1.Items.Add('One');
  ComboBox1.Items.Add('Two');
  ComboBox1.Items.Add('Three');
end;

procedure TForm1.ComboChange(Sender: TObject);
begin
  { First Try }
  ComboBox1.DroppedDown := true;

  { Second Try }
  //PostMessage((Sender as TComboBox).Handle, CB_SHOWDROPDOWN, 1, 0);

  { Grasping at straws }
  //ShowCursor(true);
end;


end.
0

There are 0 best solutions below