Link to home
Start Free TrialLog in
Avatar of petershaw9
petershaw9

asked on

Display on the ComboBox

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.
Avatar of kretzschmar
kretzschmar
Flag of Germany image

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
Following...®
ASKER CERTIFIED SOLUTION
Avatar of victor_christov
victor_christov

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
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;