This is a migrated thread and some comments may be shown as answers.

Databound Autosize not working

3 Answers 129 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chad Biggerstaff
Top achievements
Rank 1
Chad Biggerstaff asked on 31 May 2008, 05:20 AM
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.

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 02 Jun 2008, 04:10 PM
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
0
Chad Biggerstaff
Top achievements
Rank 1
answered on 02 Jun 2008, 05:06 PM
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.
0
Georgi
Telerik team
answered on 04 Jun 2008, 10:23 AM
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
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Chad Biggerstaff
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Chad Biggerstaff
Top achievements
Rank 1
Share this question
or