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

Auto width for selecting text

1 Answer 20 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nicholas Walker
Top achievements
Rank 1
Nicholas Walker asked on 15 Jul 2013, 04:52 PM
Say I have 3 items in a drop down with widths of 100px, 200px and 300px.

I set the DropDownAutoWidth to enabled.  I do not set a width property so it is defaulting to it looks like 158px.

I expand the drop down and the width of the drop down gets set to 300px, so all items are shown on one line.  I select the 300px item, the selection box is still at 158 px, so the last 162 pixels are trimmed and you can't see them.

Would it be possible to instead.

I select an item that is 100px, after selection the box trims to 100 pixels.  I select another item 300px, the selection box now turns to 300 pixels, and so fourth.

1 Answer, 1 is accepted

Sort by
0
A2H
Top achievements
Rank 1
answered on 16 Jul 2013, 11:51 AM
Hi,

Please try the below implementation

1)      1) Add a span in your aspx page

<span id="stringcontainer" style="visibility: hidden; white-space: nowrap;"></span>

2)      2) Hook the  â€śOnClientSelectedIndexChanged” event in RadComboBox

OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"

3)      3) Add the following Javascript methods to your page

function SelectedTextWidth(textToMeasure) {

                var ruler = document.getElementById("stringcontainer");

                ruler.innerHTML = textToMeasure;

                return ruler.offsetWidth;

            }

            function OnClientSelectedIndexChanged(sender, eventArgs) {

                    var stringWidth =0;

                    stringWidth = SelectedTextWidth(eventArgs.get_item()._text);

                    var combo = $find("<%= RadComboBox2.ClientID %>");

                    $(combo.get_element()).css("width", stringWidth +'px');

                    var inputArea = combo.get_inputDomElement();

                    $(inputArea).css("width", stringWidth +'px');

            }


Thanks,
A2H


Tags
ComboBox
Asked by
Nicholas Walker
Top achievements
Rank 1
Answers by
A2H
Top achievements
Rank 1
Share this question
or