PLS HELP! ComoBox list adjustment

M

MuZZy

Hi,

I just wonder if anybody could give me a hint on this:
I have a ComboBox component on the form and it has some very long sting items. When the combobox
drops down, the list of items doesn't adjust it's width to the length of the items. Is there a way
to do that, other than using third-party controls? This requirement (mean, using ComboBox class) is
mandatory for me as we in fact use it's inherited components all over the application.

Any ideas would be highly appreciated!

I'm stuck on that and really need some help...

Thank you,
Andrey
 
G

Guest

private void button2_Click(object sender, System.EventArgs e)
{
//add a new item to the combobox
comboBox1.Items.Add(textBox1.Text);
//Message box for displaying the text length and combo width length to
make testing easier
//MessageBox.Show(textBox1.Text.Length + " vs " + ((int)
comboBox1.DropDownWidth / 10));
//check the length of the item you are adding with the current
length of the dropdown
if(textBox1.Text.Length > (int) comboBox1.DropDownWidth /10)
{
//change the drop down width
comboBox1.DropDownWidth = textBox1.Text.Length * 10;
}

}

The dividing and multiplying the string length by a given value (i used 10
which is probably not optimal) is nessicary because controls are defined by
pixel width/height which is significantly smaller then character length.
Someone can probably tell you what to divide or multiply by to convert
characters to pixels and vise versa

Jake Holt
Resident Dork
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top