?
Solved

Display on the ComboBox

Posted on 1999-11-17
4
Medium Priority
?
169 Views
Last Modified: 2010-04-04
In the Combobox Item, It has items, like 'SBW    Seacon Bonded Warehouse ', all lines start with 3 characters.
When I select it, I wish the box shows the first 3 characters only. How can do this?
Thank you.
0
Comment
Question by:petershaw9
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2216062
hi petershaw9,

this will do it, if you leave the combobox

procedure TForm1.ComboBox1Exit(Sender: TObject);
begin
  combobox1.Text := copy(combobox1.Items[combobox1.ItemIndex],1,3);
end;

meikl
0
 
LVL 15

Expert Comment

by:simonet
ID: 2216303
Following...®
0
 
LVL 1

Accepted Solution

by:
victor_christov earned 200 total points
ID: 2216329
Hi petershaw9,

I had the same problem 2 mounths ago. Proposed by Kretzschmar way was not acceptable for me, so I applied a diffrent approach.

I use 3 component for this purpose : TEdit, TSpeedButton and TComboBox. TEdit is ReadOnly, TComboBox is initially unvisible. TSpeedButton activates TComboBox. Here is a simple code of my program. I hope it will be usefull for you.

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Edit1: TEdit;
    SpeedButton1: TSpeedButton;
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  With Edit1 do begin
     Left := 56; Top := 112 ; Width := 156 ;
     ReadOnly := True ;
  end;
  With SpeedButton1 do begin
     Left := 212 ; Top := 112 ; Caption := 'u' ;
     Font.Name := 'Marlett' ;
     Font.Size := 10        ;
  end;
  With ComboBox1 do begin
     Left := 56; Top := 112 ; Width := 173 ;
     Visible := False ;
  end;


end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
Var i,Ix : Integer ;
begin
  With ComboBox1 do begin
    Visible := True ;
    Ix := -1 ;
    With Items do
      for i := 0 to Count -1 do
        if Copy(Strings[i],1,3)= Trim(Edit1.Text) then
           Ix := i ;
    ItemIndex := Ix;
    SetFocus;
    KeyBd_Event(Vk_F4,0,0,0);
    KeyBd_Event(Vk_F4,0,KEYEVENTF_KeyUp,0);

  end;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  With ComboBox1 do begin
    Edit1.Text := Copy(Text,1,3);
    Visible := False ;
  end;
end;

End.



Regards Victor.
0
 
LVL 1

Expert Comment

by:men xin
ID: 2216477
Is it your means?

set combobox1's style property =csOwnerDrawFixed

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  ComboBox1.Canvas.FillRect(rect);
  if State=[odselected,odfocused,odComboboxEdit] then begin
    ComboBox1.Canvas.Textout(rect.left,Rect.top,ComboBox1.Items[Index]);
    exit;
  end;
  if state=[odselected,odfocused] then begin
    ComboBox1.Canvas.Textout(rect.left,Rect.top,copy(ComboBox1.Items[Index],0,3));
  end else begin
    ComboBox1.Canvas.TextOut(Rect.Left,Rect.top,ComboBox1.Items[Index]);
  end;
end;
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Suggested Courses

600 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