[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Combobox

Posted on 2000-01-06
23
Medium Priority
?
576 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:petershaw9
  • 12
  • 11
23 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 200 total points
ID: 2331349
Set the dropdowncount property to 0 and in the OnDropDown event handler show the form...

Cheers,

Raymond.
0
 

Author Comment

by:petershaw9
ID: 2336666
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
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2336794
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.
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 

Author Comment

by:petershaw9
ID: 2336845
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
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2336910
OK - so why no just use a normal combobox and the original answer?

Cheers,

Raymond.
0
 

Author Comment

by:petershaw9
ID: 2337184
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
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2337238
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.
0
 

Author Comment

by:petershaw9
ID: 2337294
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
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2337327
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.
0
 

Author Comment

by:petershaw9
ID: 2339663
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
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2339695
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.
0
 

Author Comment

by:petershaw9
ID: 2339865
Raymond,
Unfortunately, it still not working.

Best regards,

Peter Shaw
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2339895
What happens now? I am dead sure it is not dropping the combobox drop down...

Cheers,

Raymond.
0
 

Author Comment

by:petershaw9
ID: 2340014
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
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2340405
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.
0
 

Author Comment

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

petershaw
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2347397
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.
0
 

Author Comment

by:petershaw9
ID: 2347864
I tried it. but it was not working. I am not sure if the command(the parameters) is right or not.

petershaw
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2347920
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.
0
 

Author Comment

by:petershaw9
ID: 2351904
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

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2356087
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.
0
 

Author Comment

by:petershaw9
ID: 2364519
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
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2364555
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.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

591 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