Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1169
  • Last Modified:

Combo box without button on the right side

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
Roza
Asked:
Roza
  • 9
  • 7
  • 6
  • +4
2 Solutions
 
mokuleCommented:

Put little TPanel on top of this button
0
 
RozaAuthor Commented:
That won't do anything...

I wont to save on some space (with)...
0
 
Ivanov_GCommented:
procedure TForm1.ComboBox1Enter(Sender: TObject);
begin
  ComboBox1.Style := csDropDownList;
  ComboBox1.DroppedDown := True;
end;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Ivanov_GCommented:

  and OnCloseUp put this

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

  to go back again to csSimple style
0
 
RozaAuthor Commented:
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
 
mokuleCommented:
You want to save some space for another control ?
When the Combo is droppedDown or in normal state?
0
 
RozaAuthor Commented:
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
 
Ivanov_GCommented:
procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
  ComboBox1.Style := csSimple;
  // set focus on the form
  Self.SetFocus;
end;

what about this ?
0
 
mokuleCommented:
If this is the only problem
try this

procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
  ComboBox1.Style := csSimple;
  ActiveControl := nil;
end;
0
 
tobjectpascalCommented:
http://www.delphi32.com/vcl/965/

seems to do what you want...
0
 
RozaAuthor Commented:
tobjectpascal
TNX but not what I am searching for.

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

   put this in OnClick

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

  and this OnCloseUp

       ComboBox1.Style := csSimple;
0
 
mokuleCommented:
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
 
RozaAuthor Commented:
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
 
Ivanov_GCommented:

    one possible problem - use LARGE fonts and check
0
 
RozaAuthor Commented:
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
 
robert_marquardtCommented:
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
 
Ivanov_GCommented:

  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
 
RozaAuthor Commented:
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
 
RozaAuthor Commented:
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
 
mokuleCommented:
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
 
RozaAuthor Commented:
mokule: Sorry, but I would like to use space that dropdown arrow is using for text...
0
 
mokuleCommented:
My last word put TPanel on dropdown arrow. It resolves everything
0
 
Lee_NoverCommented:
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
 
mokuleCommented:
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
 
calinutzCommented:
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
 
calinutzCommented:
//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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 9
  • 7
  • 6
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now