5 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 17 Sep 2012, 07:49 AM
Hi John,
Try the following code snippet to achieve your scenario.
ASPX:
C#:
Please take a look into this for more information.
Hope this helps.
Regards,
Princy.
Try the following code snippet to achieve your scenario.
ASPX:
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
NoWrap
=
"true"
ondatabound
=
"RadComboBox1_DataBound"
>
</
telerik:RadComboBox
>
C#:
protected
void
RadComboBox2_DataBound(
object
sender, EventArgs e)
{
var cbox = ((RadComboBox)sender);
int
MaxWidth = 155;
foreach
(RadComboBoxItem item
in
cbox.Items)
{
int
Width = TextWidth(item.Text);
if
(Width > MaxWidth)
{
MaxWidth = Width;
}
}
cbox.DropDownWidth =
new
Unit(MaxWidth);
}
public
static
int
TextWidth(String TheText)
{
Font DrawFont =
null
;
Graphics DrawGraphics =
null
;
Bitmap TextBitmap =
null
;
try
{
TextBitmap =
new
Bitmap(1, 1);
DrawGraphics = Graphics.FromImage(TextBitmap);
DrawFont =
new
Font(
"Segoe UI"
, 12);
int
Width = (
int
)DrawGraphics.MeasureString(TheText, DrawFont).Width;
return
Width;
}
finally
{
TextBitmap.Dispose();
DrawFont.Dispose();
DrawGraphics.Dispose();
}
}
Please take a look into this for more information.
Hope this helps.
Regards,
Princy.
0
john
Top achievements
Rank 1
answered on 17 Sep 2012, 09:32 AM
Thanks. Also, whether you have any plan to integrate the feature into your RadCombox control? After all developer need to add those code for every RadCombox and it's not very not convenient.
0
Hi,
We are planning to incorporate such clientside feature in the ComboBox. At the moment it's looking very promising and the best part of it, it does not iterate over the items to find the widest item, but uses another approach instead.
Regards,
Ivan Zhekov
the Telerik team
We are planning to incorporate such clientside feature in the ComboBox. At the moment it's looking very promising and the best part of it, it does not iterate over the items to find the widest item, but uses another approach instead.
Regards,
Ivan Zhekov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Ryan Pope
Top achievements
Rank 1
answered on 30 Oct 2013, 07:54 PM
Ivan,
Did you ever get this added into RadComboboxFunctionality?
"Hi,
We are planning to incorporate such clientside feature in the ComboBox. At the moment it's looking very promising and the best part of it, it does not iterate over the items to find the widest item, but uses another approach instead."
Did you ever get this added into RadComboboxFunctionality?
"Hi,
We are planning to incorporate such clientside feature in the ComboBox. At the moment it's looking very promising and the best part of it, it does not iterate over the items to find the widest item, but uses another approach instead."
0
Princy
Top achievements
Rank 2
answered on 31 Oct 2013, 09:42 AM
Hi Ryan Pope,
Please try setting the DropDownAutoWidth property of a RadComboBox to Enabled for expanding the width of DropDownItems. By default its value is disabled.Please have a look into this help documentation for more details..
Thanks,
Princy.
Please try setting the DropDownAutoWidth property of a RadComboBox to Enabled for expanding the width of DropDownItems. By default its value is disabled.Please have a look into this help documentation for more details..
Thanks,
Princy.