Board index » cppbuilder » Small Combobox Width and Large TStrings

Small Combobox Width and Large TStrings


2007-04-10 05:22:53 AM
cppbuilder102
I have a ComboBox set as "csDropDownList" that I must fit into a very small
space. The width can only be 50. The TStrings property has text that is much
larger than 50. When this box is dropped down the text area is cut off
because the text area doesn't fit to the size of the text. I can't find any
ComboBox property to make the text area adjust to fix to the size of the
text. Is there a way to make the ComboBox adjust to the text size?
Thanks
Larry.
 
 

Re:Small Combobox Width and Large TStrings

"LarryJ" < XXXX@XXXXX.COM >wrote in message
Quote
I can't find any ComboBox property to make the text area
adjust to fix to the size of the text.
That is because there isn't any.
Quote
Is there a way to make the ComboBox adjust to the text size?
Not in the VCL, no. You would have to use the CB_SETDROPPEDWIDTH
window message directly instead. Each time you add new items to the
list, you will have to compute the longest available string length and
then send the message to the ComboBox. For example:
int iNewWidth = 0;
int iCount = ComboBox1->Items->Count;
for(int i = 0; i < iCount; ++i)
{
int iWidth =
ComboBox1->Canvas->TextWidth(ComboBox1->Items->Strings[i]);
if( iWidth>iNewWidth )
iNewWidth = iWidth;
}
ComboBox1->Perform(CB_SETDROPPEDWIDTH, iNewLength, 0);
Gambit