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

DropDownHeight Autosize

3 Answers 95 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 25 Aug 2014, 06:57 PM
Is there a way to have the DropDownList DropDownHeight be determined on drop down ("popup opened")?

3 Answers, 1 is accepted

Sort by
0
Thomas
Top achievements
Rank 1
answered on 25 Aug 2014, 07:12 PM
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();
            }
        }
0
Thomas
Top achievements
Rank 1
answered on 25 Aug 2014, 07:13 PM
Call that function from "PopupOpened" or PopupOpening
0
Stefan
Telerik team
answered on 26 Aug 2014, 10:54 AM
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.
 
Tags
DropDownList
Asked by
Thomas
Top achievements
Rank 1
Answers by
Thomas
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or