?
Solved

MouseDown on TDBComboBox

Posted on 2001-08-01
2
Medium Priority
?
544 Views
Last Modified: 2010-04-06
I want to trap the OnMouseDown on a TDBComboBox. I want to clear the box if right-mouse button is clicked on it.

There is no event for mousedown... how do I trap it?

thanks for the help.
0
Comment
Question by:espeterson
[X]
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
  • 2
2 Comments
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6341219
Try this:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure MyDBComboBoxMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TMyDBComboBox = class(TDBComboBox)
  published
    property OnMouseDown;
  end;

var
  Form1 : TForm1;
  MyDBComboBox : TMyDBComboBox;

implementation

{$R *.DFM}

procedure TForm1.MyDBComboBoxMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if ssRight in Shift then
  begin
    ShowMessage('Right Mouse Button has been Clicked...')
    // Do whatever when right mouse button is clicked...
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyDBComboBox := TMyDBComboBox.Create(self);
  with MyDBComboBox do
  begin
    Parent := Form1;
    Left := 10;
    Top := 10;
    Width := 145;
    Height := 21;
    // Define any other properties...
  end;
  MyDBCombobox.OnMouseDown := MyDBComboBoxMouseDown;
end;

end.

Cheers,

Alan
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 300 total points
ID: 6341250
Just realised that my above example did'nt totaly work so i redid it:

to make it work you just have to have a Popupmenu on the form and use the below code:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    procedure FormCreate(Sender: TObject);
    procedure MyDBComboBoxMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure PopupMenu1Popup(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TMyDBComboBox = class(TDBComboBox)
  published
    property OnMouseDown;
  end;

var
  Form1 : TForm1;
  MyDBComboBox : TMyDBComboBox;

implementation

{$R *.DFM}

procedure TForm1.MyDBComboBoxMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if ssRight in Shift then
    MyDBComboBox.Clear;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyDBComboBox := TMyDBComboBox.Create(self);
  with MyDBComboBox do
  begin
    Parent := Form1;
    Left := 10;
    Top := 10;
    Width := 145;
    Height := 21;
    PopupMenu := PopupMenu1;
    MyDBComboBox.Text := 'Test';
    OnMouseDown := MyDBComboBoxMouseDown;
    // Define any other properties...
  end;
end;

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  MyDBComboBox.Clear;
end;

end.

If you dont want to use all this code then you can just put down a DBComboBox and a PopupMenu on a form, and then Assign the PopupMenu's name value to PopupMenu property in DBComboBoxs properties. After youve done that use the below code in the PopupMenu's Popup event:

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  MyDBComboBox.Clear;
end;

This will work when you right click on the editable part of the dbcombobox but not anywhee else.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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