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

Dynamic RadDropDownList has incorrect Bottom and Height value when AutoSize = true

5 Answers 115 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 06 Mar 2016, 10:51 PM

Can't confirm if this is mentioned anywhere so I wanted to let you know just in case...

For a RadDropDownList that isn't currently visible (it's added dynamically to a panel which isn't currently in focus even though the parent form itself is loaded and visible) the .Bottom and .Height properties don't return the correct values if AutoSize = true. .Height =0 and instead of giving the correct .Bottom value it returns the .Top value - I assume this is because .Height = 0.

If I leave all code exactly as it is but set AutoSize = false then .Bottom and .Height are calculated perfectly.

This is pretty counter intuitive since the RadDropDownList is 100% established except it hasn't yet been displayed. At this point there are no items in the list though so I'm guessing that might be breaking the AutoSize.

5 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 07 Mar 2016, 05:19 PM
Hello Phil,

Thank you for writing.

Following your description, I could not reproduce the reported behavior. I am sending you attached my sample project. Could you please check if it differs from your local setup and send it back to me?

Looking forward to your reply.

Regards,
Hristo Merdjanov
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
0
Phil
Top achievements
Rank 1
answered on 07 Mar 2016, 09:31 PM

I've updated your example.
With AutoSize = true, if you set the Anchor property to include AnchorStyles.Right then .Height (and .Bottom) are broken.
With AutoSize = false, if you set the Anchor property to include AnchorStyles.Right then .Height (and .Bottom) are perfect.
I've changed my current solution to set AutoSize to false so I can properly evaluate the values (since I do the layout calculations last and all setting, including anchors, is done first). An alternative would be to always set anchors last.

I cannot attach anything other than images but if you change the click handler to this snippet you will achieve the same behaviour.

01.private void radButton1_Click(object sender, EventArgs e)
02.        {
03.            RadDropDownList ddl = new RadDropDownList();
04.            //ddl.AutoSize = false;
05.            ddl.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
06.            this.splitPanel1.Controls.Add(ddl);
07. 
08.            if (ddl.Height == 0) MessageBox.Show(String.Format("AH! This isn't good! Bottom: {0}, Height: {1}", ddl.Bottom, ddl.Height));
09. 
10.            RadDropDownList ddl2 = new RadDropDownList();
11.            ddl2.Top = ddl.Bottom + 6;
12.            this.splitPanel1.Controls.Add(ddl2);
13.        }

0
Hristo
Telerik team
answered on 08 Mar 2016, 05:02 PM
Hi Phil,

Thank you for writing back.

Adding a control to the split panel triggers the System.Windows.Forms.OnLayout method, which internally measures and arranges the drop-down list. In order to have a valid height with these settings please, make a call to the LoadElementTree method of RadDopDownList after adding it as a control to the split panel: 
private void radButton1_Click(object sender, EventArgs e)
{
    RadDropDownList ddl = new RadDropDownList();
    //ddl.AutoSize = false;
    ddl.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
    this.splitPanel1.Controls.Add(ddl);
 
    ddl.LoadElementTree();
 
    if (ddl.Height == 0) MessageBox.Show(String.Format("AH! This isn't good! Bottom: {0}, Height: {1}", ddl.Bottom, ddl.Height));
 
    RadDropDownList ddl2 = new RadDropDownList();
    ddl2.Top = ddl.Bottom + 6;
    this.splitPanel1.Controls.Add(ddl2);
}

Alternatively to this solution, you can simply add the first drop-down list object to the split panel after reading its Height and Bottom properties.

I hope this helps. Please let me know if you need further assistance.

Regards,
Hristo Merdjanov
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
0
Phil
Top achievements
Rank 1
answered on 08 Mar 2016, 10:13 PM

It seems really strange to me that we should have to add calls to LoadElementTree() every time AutoSize is enabled and a parent container isn't visible and we want to access basic layout properties for a control. Typically we want to ensure a layout is set before making a container visible so there are less calculations and drawing is faster and smoother - not such an issue nowadays but it's still best practice.

As a point of interest, I repeated the same process with ComboBox instead of RadDropDownList and all properties were perfectly accessible in typical .NET fashion.

May I request that this is handled internally in future? So when layout properties are requested but the layout hasn't being handled yet that it will get evaluated and then the correct values will be available?

Thanks for all your assistance Hristo, across the threads and support tickets I've learned quite a bit more about Telerik so I'm starting to get a better understanding of how to work with it.

0
Hristo
Telerik team
answered on 09 Mar 2016, 03:52 PM
Hi Phil,

Thank you for writing back.

In this particular case, the size appears to be changed after calling the System.WindowsForms.ScrollableControl.OnLayout method. We will consider handling such or a similar scenario internally.

Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
DropDownList
Asked by
Phil
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Phil
Top achievements
Rank 1
Share this question
or