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

DropDownList popup location after resizing items width

1 Answer 106 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 19 Jul 2015, 11:00 AM

Hi,

 

I used this solution to increase my DropDownList popup when item text is longer than ​DropDownList size. But when I open the DropDownList for the first time, it goes off the screen (my DropDownList is at the right edge of the form and popup isn't positioned correctly and goes right off the screen).

​Then when I ​close and ​open DropDownList, the popup position will be correct and after that everything is OK.

 

Should I add something at the end of "PopupOpened" event after resizing items?

 

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 21 Jul 2015, 01:33 PM
Hello Kevin,

Thank you for writing.

I was not able to reproduce the observed behavior. This is why I wanted to ask you wich is the exact version  that you are using?

Additionally, I want to suggest you a slightly different solution. You can use the PopupOpening event and set the width directly like this:
public RadForm1()
{
    InitializeComponent();
    for (int i = 0; i < 5; i++)
    {
        radDropDownList1.Items.Add("item " + i);
    }
    radDropDownList1.Items.Add("Item with very long text, Item with very long text");
    radDropDownList1.PopupOpening += PopupOpening;
    
}
 
void PopupOpening(object sender, CancelEventArgs e)
{
    int width = -1;
    foreach (var item in radDropDownList1.Items)
    {
        int itemWidth = TextRenderer.MeasureText(item.Text, radDropDownList1.Font).Width;
        if (width < itemWidth)
        {
            width = itemWidth;
        }
    }
 
    radDropDownList1.DropDownListElement.Popup.Width = width + 5;
}

I hope this helps. I am looking forward to your reply.

Regards,
Dimitar
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
Tags
DropDownList
Asked by
Kevin
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or