Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MouseDown on TDBComboBox

Posted on 2001-08-01
2
Medium Priority
?
554 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

618 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