Solved

MouseDown on TDBComboBox

Posted on 2001-08-01
2
539 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 100 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

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 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