Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to see entire text in a Combobox 1

Status
Not open for further replies.

goranm

Programmer
Dec 18, 2001
247
SE
Hi !

I´m using Delphi 5.

I have a standard combobox in my form.

The width of the box is not as wide as the items that are in the box.

What I want to happen is that the dropdown itself will be as long as needed so you can see all the text.

I have not found any settings for this.
Is it possible ?

/Goran
 
To set the length of the dropdown items you can either use

Code:
  TheComboBox.Perform(CB_SETDROPPEDWIDTH, NeededWidth, 0);
or
Code:
  SendMessage(TheComboBox.handle, CB_SETDROPPEDWIDTH, NeededWidth, 0);
 
Thank you for your answer.

Where do I put this code ?

I can´t find a property for the combobox in the object inspector that is named "SetDroppedWidth".

/Goran
 
Just use it in the DropDown event of the ComboBox like this:
Code:
procedure TForm1.ComboBox1DropDown(Sender: TObject);
begin
  ComboBox1.Perform(CB_SETDROPPEDWIDTH, 300, 0);
end;

 
That worked great, thank you.

Do you even know how to make the "NeededWidth" variable, so it always is as wide as the longest word.

/Goran
 
That is hard since the font in the combobox may vary. And in different types of fonts the length of the letters in pixels varies also.

But basically you have to get the length (Length function) of the longest item. Then multiply it by the average character size.

Pikkunero
 
Ok,
I tried that just before your last post, but I didn´t know how to get the average character size,
so I just tested and found out that if I multiplied with 6 in my case it became acceptable.

Thanks again.

/Goran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top