Calculating ComboBox DropDownWidth in C#
Posted
by Jim Fell
on Stack Overflow
See other posts from Stack Overflow
or by Jim Fell
Published on 2010-05-24T15:42:32Z
Indexed on
2010/05/24
15:51 UTC
Read the original article
Hit count: 305
In my application a ComboBox gets resized, so that it is smaller. How do I re-calculate the DropDownWidth property? I know how to set it, but I'd prefer to calculate the proper width because its contents changes. Preferabley, I was thinking of something along these lines:
int iMaxLen = 0;
foreach item in comboBoxList
{
iMaxLen = (item.Length > iMaxLen) ? item.Length : iMaxLen;
}
comboBoxList.DropDownWidth = iMaxLen;
Thanks.
© Stack Overflow or respective owner