Solved

Combo box without button on the right side

Posted on 2004-04-16
27
1,039 Views
Last Modified: 2012-05-04
I want to have combo box without button on the right side (to click on it and combo will drop down a list).

I want when user clicks on combo it droppes down.

How to do that?

I tryed to set ComboBox style to csSimple, but then I can not drop down item list from it.

Thank you.
0
Comment
Question by:Roza
  • 9
  • 7
  • 6
  • +4
27 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10841401

Put little TPanel on top of this button
0
 
LVL 2

Author Comment

by:Roza
ID: 10841461
That won't do anything...

I wont to save on some space (with)...
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10841513
procedure TForm1.ComboBox1Enter(Sender: TObject);
begin
  ComboBox1.Style := csDropDownList;
  ComboBox1.DroppedDown := True;
end;
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10841528

  and OnCloseUp put this

procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
  ComboBox1.Style := csSimple;
end;

  to go back again to csSimple style
0
 
LVL 2

Author Comment

by:Roza
ID: 10841557
That would be sollution but...

Tryed that already
-when combo box closes I can not do anything more with it. Only possibility is to exit from control and enter again.
0
 
LVL 17

Expert Comment

by:mokule
ID: 10841628
You want to save some space for another control ?
When the Combo is droppedDown or in normal state?
0
 
LVL 2

Author Comment

by:Roza
ID: 10841671
In normal state of course.

See how Ivanov G sollution works. It's ok to me. Problem is only when combo closes down. It should be clickable again.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10841702
procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
  ComboBox1.Style := csSimple;
  // set focus on the form
  Self.SetFocus;
end;

what about this ?
0
 
LVL 17

Expert Comment

by:mokule
ID: 10841717
If this is the only problem
try this

procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
  ComboBox1.Style := csSimple;
  ActiveControl := nil;
end;
0
 
LVL 4

Expert Comment

by:tobjectpascal
ID: 10841743
http://www.delphi32.com/vcl/965/

seems to do what you want...
0
 
LVL 2

Author Comment

by:Roza
ID: 10841939
tobjectpascal
TNX but not what I am searching for.

mokule&Ivanov_G: Focus should remain on "ComboBox".
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10842001

   put this in OnClick

       ComboBox1.Style := csDropDownList;
       ComboBox1.DroppedDown := True;

  and this OnCloseUp

       ComboBox1.Style := csSimple;
0
 
LVL 17

Expert Comment

by:mokule
ID: 10842077
Why don't You want to use my solution with TPanel.
It' simple.
Works perfectly.
If You want You can place another control so it covers some part of the TPanel.
Where is the problem, I can't see any.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 2

Author Comment

by:Roza
ID: 10842095
I've tryed all of this sollutions already and then do not work. That's why I asked question here.

I have already tryed to create my own combo box from TCustomCombo, but I can not find procedure where TCustomCombo actualy paints.
Sollution is probably in way of overriding WMPaint of TComboBox and not painting button...

0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10842108

    one possible problem - use LARGE fonts and check
0
 
LVL 2

Author Comment

by:Roza
ID: 10842140
mokule: Yes it works, but...
My spare sollution is to have one TEdit and one TComboBox. Now when user enters on TEdit, TComboBox shows up and receives focus. On TComboBox OnExit again TEdit shows up...
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 10842180
The idea is bad.
The component will look like a TEdit and a user would expect TEdit behavior.
The drop down arrow is what the name says an indicaton that a drop down list is to be expected.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10842281

  my last suggestion :

procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_DOWN then
    begin
      ComboBox1.Style       := csDropDown;
      ComboBox1.DroppedDown := True;
    end;
end;

procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
  ComboBox1.Style := csSimple;
end;
0
 
LVL 2

Author Comment

by:Roza
ID: 10842304
robert_marquardt:
I know, but in about 80% user selects item with shortcut key.
I usualy use one with drop down arrow, but here I would like to have that space drop down arrow is using.

I use dbcombobox aligned with dbgrid columns with other edits. Dbgrid has smaller font than edits have and if I place a combo box with drop down arrow it uses 50% more space than normal edit would.
0
 
LVL 2

Author Comment

by:Roza
ID: 10842389
Hm.. some strange explanation:

>I use dbcombobox aligned with dbgrid columns with other edits. Dbgrid has smaller font than edits have and if I place a combo box with >drop down arrow it uses 50% more space than normal edit would.

I have dbgrid and on bottom of the grid some edits and combobox (used for inputs) aligned with dbgrid columns...

Sounds better I think..
0
 
LVL 17

Expert Comment

by:mokule
ID: 10842529
What about such solution

procedure TForm1.ComboBox2CloseUp(Sender: TObject);
begin
  ComboBox2.Width := 100;
end;

procedure TForm1.ComboBox2DropDown(Sender: TObject);
begin
  ComboBox2.Width := 200;
end;
0
 
LVL 2

Author Comment

by:Roza
ID: 10842581
mokule: Sorry, but I would like to use space that dropdown arrow is using for text...
0
 
LVL 17

Expert Comment

by:mokule
ID: 10842619
My last word put TPanel on dropdown arrow. It resolves everything
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 10856962
mokule: what would that help ? it's not about making that arrow invisible, it's about making that space usable for editing
placing a panel over doesn't make it usable at all ..

roza: what about using a T(DB)Edit and displaying a T(DB)ListBox under it
you can add some "automation" on the Edits OnKeyUp and OnEnter/Exit events
0
 
LVL 17

Accepted Solution

by:
mokule earned 50 total points
ID: 10857118
Lee Nover: Yes it makes it usable. Can't imagine ? Here You are.

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Panel1: TPanel;
    ComboBox2: TComboBox;
    Panel2: TPanel;
    ComboBox3: TComboBox;
    Panel3: TPanel;
    ComboBox4: TComboBox;
    Panel4: TPanel;
    ComboBox5: TComboBox;
    Panel5: TPanel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

end.
{----------------------------}
object Form1: TForm1
  Left = 192
  Top = 114
  Width = 602
  Height = 195
  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 = 16
    Top = 24
    Width = 121
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    TabOrder = 0
    Items.Strings = (
      '1'
      '2'
      '3'
      '4'
      '5')
  end
  object Panel1: TPanel
    Left = 118
    Top = 23
    Width = 25
    Height = 25
    BevelOuter = bvNone
    TabOrder = 1
  end
  object ComboBox2: TComboBox
    Left = 120
    Top = 24
    Width = 121
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    TabOrder = 2
    Items.Strings = (
      '1'
      '2'
      '3'
      '4'
      '5')
  end
  object Panel2: TPanel
    Left = 222
    Top = 23
    Width = 25
    Height = 25
    BevelOuter = bvNone
    TabOrder = 3
  end
  object ComboBox3: TComboBox
    Left = 224
    Top = 24
    Width = 121
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    TabOrder = 4
    Items.Strings = (
      '1'
      '2'
      '3'
      '4'
      '5')
  end
  object Panel3: TPanel
    Left = 326
    Top = 23
    Width = 25
    Height = 25
    BevelOuter = bvNone
    TabOrder = 5
  end
  object ComboBox4: TComboBox
    Left = 328
    Top = 24
    Width = 121
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    TabOrder = 6
    Items.Strings = (
      '1'
      '2'
      '3'
      '4'
      '5')
  end
  object Panel4: TPanel
    Left = 430
    Top = 23
    Width = 25
    Height = 25
    BevelOuter = bvNone
    TabOrder = 7
  end
  object ComboBox5: TComboBox
    Left = 432
    Top = 24
    Width = 121
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    TabOrder = 8
    Items.Strings = (
      '1'
      '2'
      '3'
      '4'
      '5')
  end
  object Panel5: TPanel
    Left = 534
    Top = 23
    Width = 25
    Height = 25
    BevelOuter = bvNone
    TabOrder = 9
  end
end
{----------------------------}
0
 
LVL 11

Assisted Solution

by:calinutz
calinutz earned 250 total points
ID: 10858121
Place a EditBox on Top of the ComboBox and then

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
If key=VK_DOWN then
begin
ComboBox1.DroppedDown:=true;
Form1.ActiveControl:=ComboBox1;
end;
end;

procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
Form1.ActiveControl:=Edit1;
end;
0
 
LVL 11

Expert Comment

by:calinutz
ID: 10858145
//and this also

procedure TForm1.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
ComboBox1.DroppedDown:=true;
Form1.ActiveControl:=ComboBox1;
end;

procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
Edit1.Text:=ComboBox1.Text;
Form1.ActiveControl:=Edit1;
end;
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now