Databound Autosize not working

4 posts, 0 answers
  1. Chad Biggerstaff
    Chad Biggerstaff avatar
    13 posts
    Member since:
    Apr 2005

    Posted 31 May 2008 Link to this post

    I was specifically looking for a winforms combobox with autosizing and I noticed (in your documentation) you support this.  However it doesn't seem to be working.  I'm not sure if it's because I'm using a databound datasource or exactly why.  I want the combobox to automatically set it's width to the length of the text contained within it.  I'm using version 6.1.0.0.
  2. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 02 Jun 2008 Link to this post

    Hi Chad Biggerstaff,

    Thank you for writing us.

    As far as I understand, you would like to change the width of the textbox part of the RadComboBox control. However, the AutoSize property has been implemented in the base class for all controls (System.Windows.Forms.Control) and although it is always present, its value is not applied to the layout of some of them. For example, the RadComboBox.AutoSize property does not affect the size of the control at all.

    However, thanks to the Telerik Presentation Framework you can work around this limitation. You have to set the StretchHorizontally property of the necessary elements of the control structure to false. Then, in the handler of the TextChanged event, you will change the size according to the length of the current text. Here is the code:

        public Form1()  
        {  
              
            InitializeComponent();  
     
            this.radComboBox3.RootElement.StretchHorizontally = false;  
            this.radComboBox3.ComboBoxElement.TextBoxElement.TextBoxItem.StretchHorizontally = false;  
        }  
     
        private void radComboBox3_TextChanged(object sender, EventArgs e)  
        {  
            int width = TextRenderer.MeasureText(radComboBox3.Text, radComboBox3.Font).Width;  
            int height = radComboBox3.ComboBoxElement.TextBoxElement.TextBoxItem.HostedControl.Size.Height;  
            radComboBox3.ComboBoxElement.TextBoxElement.TextBoxItem.HostedControl.Size = new Size(width, height);  
        } 

    I hope this helps. If you have any additional questions, please don't hesitate to write us again. 

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Chad Biggerstaff
    Chad Biggerstaff avatar
    13 posts
    Member since:
    Apr 2005

    Posted 02 Jun 2008 Link to this post

    Thank you for the sample code. 
    I am wondering, I guess I'd like to put in a request for, in future builds if you could add that to the sourcecode so that you look at the base Autosize property and do that code automatically if it's set to true.  I think this would be a nice addition to your control and (I tried a few others) I am not aware of another combobox on the market that does this so it would be another selling point.  Since the property is shown in designview I would imagine others (like myself) would expect such to be the behavior of the control.
  5. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 04 Jun 2008 Link to this post

    Hi Chad Biggerstaff,

    Thank you for your suggestion.

    Our intention is to have RadComboBox behave just like the standard Microsoft combobox. The AutoSize property was left visible due to an omission, and we will make it invisible to prevent further misunderstanding.

    In the future, once we implement the functionality you have described, we will make this property visible to enable it.

    I have updated your Telerik points for the suggestion.

    Best wishes,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top