ComboBox
Hello!
Is there any way to prevent the user from dragging data or typing text inside a comboBox?
If not, Is there an alternative for comboBoxes that DOESN'T allow the user to type in anything?
Thanks!
Ali
[240 byte] By [
khanafer] at [2007-11-19 10:48:09]

# 2 Re: ComboBox
Awesome!
Thanks man! It works fine!
Another Question:
Do you know how would I be able to control the Width of the dropdownMenue.
I tried using the DropDownWidth property but I would prefer having horizontal scrolling bar.
I tried to set the DropDownWidth to the longest string I have in the list but it seems that there is a difference in the range of DropDownWidth and String::Length!
int ItemMaxLength = this.DropMenue.Items[0].ToString().Length;
for(int i=0; i<this.Menue.Items.Count; i++)
{
if(this.Menue.Items[i].ToString().Length > ItemMaxLength)
ItemMaxLength = this.Menue.Items[i].ToString().Length;
}
# 3 Re: ComboBox
Awesome!
Thanks man! It works fine!You are welcome..
Another Question: Ok..But it's generally better to start new threads for new Qs..and leave the original thread for followups..
I tried to set the DropDownWidth to the longest string I have in the list but it seems that there is a difference in the range of DropDownWidth and String::Length! Sure String::Length is the number of characters.
DropDownWidth is calculated in pixels.
I wish this code can help :
int ItemMaxLength = this.cmb.Items[0].ToString().Length;
int maxLenIndex=0;
for(int i=0; i<this.cmb.Items.Count; i++)
{
if(this.cmb.Items[i].ToString().Length > ItemMaxLength)
{
ItemMaxLength = this.cmb.Items[i].ToString().Length;
maxLenIndex=i;
}
}
//MessageBox.Show(ItemMaxLength.ToString());
//Get the width :
Graphics gx= cmb.CreateGraphics();
SizeF s=gx.MeasureString(cmb.Items[maxLenIndex].ToString(),cmb.Font);
cmb.DropDownWidth=(int)s.Width;
gx.Dispose();
where cmb is the name of the combobox
hspc at 2007-11-9 1:51:41 >
