DropDownHeight Autosize

4 posts, 0 answers
  1. Thomas
    Thomas avatar
    7 posts
    Member since:
    Aug 2014

    Posted 25 Aug 2014 Link to this post

    Is there a way to have the DropDownList DropDownHeight be determined on drop down ("popup opened")?
  2. Thomas
    Thomas avatar
    7 posts
    Member since:
    Aug 2014

    Posted 25 Aug 2014 in reply to Thomas Link to this post

    Just figured out a way:

    private void CalculateSize(RadDropDownList list)
            {
                float height = 0;
     
                for (int x = 0; x < list.Items.Count(); x++)
                {
                    height += list.Items[x].MeasuredSize.Height;
                }
     
                height += 2;
                height = (height > list.DropDownMaxSize.Height) ? list.DropDownMaxSize.Height : (int)height;
     
                if (list.DropDownHeight != height)
                {
                    list.DropDownHeight = (int)height;
     
                    // Refresh?
                    list.CloseDropDown();
                    list.ShowDropDown();
                }
            }
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Thomas
    Thomas avatar
    7 posts
    Member since:
    Aug 2014

    Posted 25 Aug 2014 in reply to Thomas Link to this post

    Call that function from "PopupOpened" or PopupOpening
  5. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 26 Aug 2014 Link to this post

    Hello Thomas,

    I can confirm that the PopupOpened/PopupOpening events are suitable for the purpose. Since by this time the drop down height is already set, the "refresh" is needed. 

    I would also like to mention that while your function will work when the AutoSizeItems = true, for the rest of the cases one can use the following property to retrieve the item's height:
    radDropDownList1.DropDownListElement.ItemHeight

    I hope that you find this information useful.

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top