Link to home
Start Free TrialLog in
Avatar of petershaw9
petershaw9

asked on

Combobox

How can I click on the combobox button, but I don't want it shows the drop down list, I want to show my another form.

Thank u

PeterShaw9
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of petershaw9
petershaw9

ASKER

Raymond

Your suggestion is correct. But I found I did explained my question properly. so I still cannot use your answer.
I what to use dbcombobox linking to a SQL table. then I click the button on the dbcombobox, a second form shows, then I select a value from a dbgrid on the second form, click OK button, that value shows on the dbcombobox on the first form. then I can click [ost button to save the change. The reason why I need use dbcombobox is other dataware componnents are dbcomboboxes.

Thanks

Petershaw9
Perhaps you could replace the TDBCombobox with a TDBEdit and a little button with the combo drop down button on it.

From your description it sounds as though you want the cosmetic appearance of the combobox, but not the behaviour. Is that correct?

Cheers,

Raymond.
Hi! Raymond,

U are right. I drew a picture of the combobox button. I put the picture on the TImage and set the image just beside the dbEdit. It looks like the combobox but the at the juntion of the dbEdit and Image, there is  slight difference. So I think it is better to use real combobox but change the behaviour. I tried to use sendmessage(combobox.handle, cb_showdropdown, 0 , 0); but it doesn't work. I don't know why?

PeterShaw9
OK - so why no just use a normal combobox and the original answer?

Cheers,

Raymond.
Raymond,

I tried to use your first answer. Click on the combobox button and shows a blank form, then close the blank form, everything is OK. But when I used it in my application, problem occurred. When the second form shows, I selected a value from a datagrid in the second form, then click OK button. the second from closed and the value appeared on the combobox of the first form, but at same time the combobox's dropdown list occurred! strange!
Do u know why my sendmessage does not work? Does the delphi combobox override it in someway?

Petershaw9
This is strange - if the drop down height is zero it doesn't show anything!

I assume you are doing ComboBox1.text := TheText;  ?

What do you see in the drop down box? And what delphi version are you using?

Cheers,

Raymond.
Hi! Raymond,
Yes, I am doing ComboBox1.text := TheText;

The drop down box is blank, nothing inside. I am using Delphi 5.

Best regards

PeterShaw9
Below is the source for a sample project I wrote to test this - it works fine...


DPR file:

program Combo2Project;

uses
  Forms,
  Unit6 in 'Unit6.pas' {Form1},
  Unit7 in 'Unit7.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

form1:

object Form1: TForm1
  Left = 215
  Top = 139
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ComboBox1: TComboBox
    Left = 296
    Top = 104
    Width = 145
    Height = 21
    DropDownCount = 0
    ItemHeight = 13
    TabOrder = 0
    Text = 'ComboBox1'
    OnDropDown = ComboBox1DropDown
  end
end

unit for form1:
unit Unit6;

interface

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

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

var
  Form1: TForm1;

implementation

uses Unit7;

{$R *.DFM}

procedure TForm1.ComboBox1DropDown(Sender: TObject);
begin
  form2.showmodal;
  ComboBox1.text := 'ffff';
end;

end.

form2:

object Form2: TForm2
  Left = 397
  Top = 240
  Width = 696
  Height = 480
  Caption = 'Form2'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 128
    Top = 96
    Width = 75
    Height = 25
    Caption = 'Button1'
    ModalResult = 1
    TabOrder = 0
  end
end

unit for form2:

unit Unit7;

interface

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

type
  TForm2 = class(TForm)
    Button1: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

end.

I hope this helps...

Cheers,

Raymond.
Raymond,
I know your one works. because you assign combobox's text in the dropdown event handler, and your form2 do nothing.
 The following is my code. I assign combobox's text in the form2's button1click. In this way, it doesn't work.


program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

unit1.dfm
object Form1: TForm1
  Left = 235
  Top = 107
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ComboBox1: TComboBox
    Left = 104
    Top = 72
    Width = 145
    Height = 21
    DropDownCount = 0
    ItemHeight = 13
    TabOrder = 0
    Text = 'ComboBox1'
    OnDropDown = ComboBox1DropDown
  end
end


Unit1.pas
unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation
uses unit2;
{$R *.DFM}

procedure TForm1.ComboBox1DropDown(Sender: TObject);
begin
  form2.ShowModal;
end;

end.



unit2.dfm
object Form2: TForm2
  Left = 235
  Top = 107
  Width = 696
  Height = 480
  Caption = 'Form2'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 256
    Top = 120
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
end

Unit2.pas

unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation
uses unit1;
{$R *.DFM}

procedure TForm2.Button1Click(Sender: TObject);
begin
  form1.ComboBox1.Text := 'Test';
  form2.Close;
end;

end.

Best regards

Peter shaw
I see new! It hasn't dropped the drop down, it just hasn't redrawn the combo properly after hiding the second form.

When the second form shows, move it so that the combo is visible on the first form before closing the second form!

Add this after the form2.showmodal line to fix it:

  ComboBox1.repaint;

Cheers,

Raymond.
Raymond,
Unfortunately, it still not working.

Best regards,

Peter Shaw
What happens now? I am dead sure it is not dropping the combobox drop down...

Cheers,

Raymond.
Raymond,
How about send a mouse click message to the combobox when form2 is creating?
There is a WM_LBUTTONDOWN, but I don't know how to use it.
I tried sendmessage(form1.combobox1.handle, MK_LBUTTON, 104, 41); but it doesn't work. Problem is the last two parameters.

Peter Shaw
I don't see how this helps. You have already clicked on the button in the combo before showing the second form!

I am using D5. What version are you using?

Cheers,

Raymond.
Raymond,
U right. but how about the sendmessage(combobox.handle, cb_showdropdown, 0, 0);
I am using delphi5 too.

petershaw
Doing that will tell the drop down to drop-down, but I'm not sure if the OnDropDown event will fire. Try it!

Cheers,

Raymond.
I tried it. but it was not working. I am not sure if the command(the parameters) is right or not.

petershaw
The line looks fine...

Perhaps you could try doing Application.ProcessMessages in the OnDropDown event handler. But again, I don't think there is a problem with anything dropping down.

Can you describe exactly what happens that should not...

Cheers,

Raymond.
I wish the combobox works like: put a edit box and a button together. That means the dropdown never occurs.

best regards and have good weekend

Peter Shaw

Yes, I understand that is how you want it to work - what I am not sure of is exactly what is going wrong!

Cheers,

Raymond.
Hi!
The problem is after I select a value on the other form, and make the combobox text = the value, close the form, the dropdown of the combobox still appears.

Best regards

Peter Shaw
When I first tried it I though it was drawing the drop down, but then I noticed that the rectangle I was seeing was placed directly to the left of the drop down button - in other words it wasn't the drop down at all, but a partially drawn edit box area of the combo. Thats why I added the repaint...

Is the box you see to the left of, or also below the drop down button?

Cheers,

Raymond.