How to set Max DropDown Width?

5 posts, 1 answers
  1. tungnt185
    tungnt185 avatar
    40 posts
    Member since:
    Aug 2009

    Posted 04 Jun 2010 Link to this post

    Hello Telerik team,

    I've a control Combo inherit from RadComboBox, I use it in many form with many different width.
    I want to set max dropdown width of this combobox to one's width.
    But I realize RadComboBox only have MinDropDownWidthProperty and it's read only property.
    So how can I set it?

    Thanks
  2. Answer
    Dani
    Admin
    Dani avatar
    848 posts

    Posted 07 Jun 2010 Link to this post

    Hello Taufik Hidayat,

    Thank you for contacting us for advice.

    Currently the RadComboBox does not provide such a property as MaxDropDownWidth

    There are two ways in which you can force RadComboBox  to accept a MaxWidth of its drop down popup.

    I. The fastest and easiest way is to create an element to serve as an ItemsPanel and set a MaxWidth to that element like so:
    <telerik:RadComboBox HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="120">
      <telerik:RadComboBox.ItemsPanel>
          <ItemsPanelTemplate>
             <StackPanel Orientation="Vertical" MinWidth="100" MaxWidth="160" />
          </ItemsPanelTemplate>
      </telerik:RadComboBox.ItemsPanel>
      <telerik:RadComboBoxItem Content="Item 1" />
      <telerik:RadComboBoxItem Content="Item 2" />
      <telerik:RadComboBoxItem Content="Item 3" />
    </telerik:RadComboBox>


    II. You can alternatively change the MaxWidth of the RadComboBox drop down area by editing the default theme of RadComboBox.  To do that, follow these steps:

    1. Open your project in Blend and with RadComboBox selected  go to Object-> Edit Template -> Edit a Copy
    2. Search for a Control Template with an x:Key="NonEditableComboBox"
    3. Inside, find Popup x:Name="PART_Popup"
    4. Add a MaxWidth property that equals a value which you see fit to your needs.

    I hope you find this information helpful. Please, contact us again for any further help.

    All the best,
    Dani
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. tungnt185
    tungnt185 avatar
    40 posts
    Member since:
    Aug 2009

    Posted 07 Jun 2010 Link to this post

    Thanks Dani,
    I've solve my problem with your suggest.
    I'm using your fist way:

     <telerikInput:RadComboBox x:Name="cboCombo" 
                                      IsEditable="True" 
                                      Height="22" 
                                      telerik:TextSearch.TextPath="ValueField" 
                                      SelectedValuePath="ValueField" 
                                      IsFilteringEnabled="True" 
                                      IsMouseWheelEnabled="True" 
                                      IsTextSearchEnabled="True" 
                                      TextSearchMode="Contains" 
                                      ItemTemplate="{StaticResource ComboBoxWithTooltip}" 
                                      > 
                <telerikInput:RadComboBox.ItemsPanel> 
                    <ItemsPanelTemplate> 
                        <VirtualizingStackPanel Orientation="Vertical" x:Name="iptCombo" Width="{Binding ActualWidth, ElementName=cboCombo, Mode=OneWay, Converter={StaticResource CBWidthConverter}}" /> 
                    </ItemsPanelTemplate> 
                </telerikInput:RadComboBox.ItemsPanel> 
            </telerikInput:RadComboBox> 
    My Converter:
    Imports System.Windows.Data 
     
    Public Class CBWidthConverter 
        Implements IValueConverter 
     
        Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert 
            If value IsNot Nothing Then 
                Return value - 20 
            Else 
                Return 0 
            End If 
        End Function 
     
        Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack 
            Throw New NotImplementedException() 
        End Function 
     
    End Class 




    Thanks for your help.
  5. Swapna
    Swapna avatar
    1 posts
    Member since:
    Feb 2014

    Posted 11 Sep 2015 in reply to Dani Link to this post

    Hello TelerikTeam,

    This post is really helpful.  But, I have another requirement that the dropdown width to be extended towards ​left rather than right aligning by radcombo's end. Would you please let me know how to achieve this?  I have added the picture how it should look like.

    Appreciate your help in this regard.

    Thanks and Regards,

    Swapna

     

  6. Nasko
    Admin
    Nasko avatar
    585 posts

    Posted 14 Sep 2015 Link to this post

    Hello Swapna,

    In order to achieve the desired appearance you need to modify the default Template of RadComboBox. By setting Placement property of the Popup named x:Name="PART_Popup" to Left and the VerticalOffset and HorizontalOffset to the ActualHeight and ActualWidth of the control the desired could be achieved.

    We have created a sample project that demonstrates that and you could run and evaluate it. Please, notice that Implicit Styles were used.

    Hopes this helps.

    Regards,
    Nasko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner