We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

ComboBoxAdv and dropdownwidth

Hi, is there a possibility to automatically set the width of the drop down area (DropDownWidth property) in comboboxadv depending on the content of the drop down? Thanks in advance, Christian

3 Replies

CR Christian Rattat February 1, 2006 09:33 AM UTC

I just forgot this: We use SF Suite 3.0.1.0 (we plan to update to 4.1 soon). Thanks, Christian >Hi, > >is there a possibility to automatically set the width of the drop down area (DropDownWidth property) in comboboxadv depending on the content of the drop down? > >Thanks in advance, >Christian


AR Anupama Roy Syncfusion Team February 1, 2006 10:55 AM UTC

Hi Christian, We cannot set the DropDownWidth automatically depending on the content of the dropDown.However,you can iterate through each added item and store the longest item''s length and measure the specified string that is drawn with specified font.Then you can assign this new width to the DropDownWidth property as illustrated below. Graphics g = this.comboBoxAdv1.CreateGraphics(); this.comboBoxAdv1.DropDownWidth =longest.Length ; int offset = Convert.ToInt32(Math.Ceiling(g.MeasureString(" ",this.comboBoxAdv1.Font).Width)); int newwidth = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(g.MeasureString(longest, this.comboBoxAdv1.Font).Width ))) + offset; this.comboBoxAdv1.DropDownWidth =newwidth; Please take a look at the sample attached. Regards, Anu.

trial_combo.zip


CR Christian Rattat February 2, 2006 05:23 AM UTC

Hi, this works for me! Thanks, Christian > >Hi Christian, > >We cannot set the DropDownWidth automatically depending on the content of the dropDown.However,you can iterate through each added item and store the longest item''s length and measure the specified string that is drawn with specified font.Then you can assign this new width to the DropDownWidth property as illustrated below. > >Graphics g = this.comboBoxAdv1.CreateGraphics(); > >this.comboBoxAdv1.DropDownWidth =longest.Length ; >int offset = Convert.ToInt32(Math.Ceiling(g.MeasureString(" ",this.comboBoxAdv1.Font).Width)); > >int newwidth = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(g.MeasureString(longest, this.comboBoxAdv1.Font).Width ))) + offset; > >this.comboBoxAdv1.DropDownWidth =newwidth; > >Please take a look at the sample attached. > >Regards, > >Anu. > >

trial_combo.zip

Loader.
Live Chat Icon For mobile
Up arrow icon