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

ComboBox AutoWidth?

1 Answer 720 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Matthias
Top achievements
Rank 1
Matthias asked on 12 Jul 2011, 06:03 AM
Hi there!

Is there are feature which autosizes a combobox due to its content?
I guess I found something for the dropdown-width, but it would be nice to have something similar for the box itself.

Best Regards,
Matthias

1 Answer, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 13 Jul 2011, 08:53 AM
Hello,

The following code shows how the RadComboBox sizes itself to its selected item:

<Window x:Class="WpfApplication9.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Border Width="300" VerticalAlignment="Center" BorderThickness="1" BorderBrush="Black">
            <telerik:RadComboBox HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4">
                <telerik:RadComboBoxItem Content="Small Item" />
                <telerik:RadComboBoxItem Content="Really Large Item" />
                <telerik:RadComboBoxItem Content="The longest one possible" />
            </telerik:RadComboBox>
        </Border>
    </Grid>
</Window>

However I believe this is not the autosizing you reffer to. You could always use the MinWidth, MaxWidth and Width of the combo but this is kind of obvious.

Could you possibly send us a screenshot of your combo and draw us which sizes are not correctly set?

The ComboBox will not size itself to the sizes within it's drop down because the items in the popup has no visual elements generated prior to the popup opening. Also in virtualizing mode using hundreds of items this would be serious performance hit measuring all of them to determine a RadComboBox width.

I would recommend you to just set a slightly larger width on the RadComboBox than the average RadComboBoxItem width.

Best wishes,
Pana
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
ComboBox
Asked by
Matthias
Top achievements
Rank 1
Answers by
Pana
Telerik team
Share this question
or