First off, I'm ecstatic that this has been developed... a step in the right direction! However, I have one tiny suggestion and it's purely from a UI perspective.
I think if the calculated drop down width is less than the RadComboBox width, it should "default" to the RadComboBox width. If you view my attachment (the too short one), you'll see what happens.
I love that this is done on the client side and would really love to know if there's a work around. Otherwise, I think I'm going to use my "in house" method which is done via server side (and isn't as efficient). This isn't code completely written by me, but I'll post what I currently have in case there are any suggested workarounds or if others are interested.
I have a general utility that calculates the width of text:
And then I have an extension method:
So, in my code behind I just have something like:
rcbSalesReps.DropDownWidth = rcbSalesReps.AutoDropDownWidth();
Just something to consider. To me, if I look at the attachments, I think the "just right" version looks much better than the "too short" one.
I'm open to any ideas or suggestions!
Thanks,
Andrew
I think if the calculated drop down width is less than the RadComboBox width, it should "default" to the RadComboBox width. If you view my attachment (the too short one), you'll see what happens.
I love that this is done on the client side and would really love to know if there's a work around. Otherwise, I think I'm going to use my "in house" method which is done via server side (and isn't as efficient). This isn't code completely written by me, but I'll post what I currently have in case there are any suggested workarounds or if others are interested.
I have a general utility that calculates the width of text:
public
static
int
TextWidth(
string
text,
string
fontName =
"Segoe UI"
,
float
fontSize = 15)
{
using
(var textBitmap =
new
Bitmap(1, 1))
{
using
(var drawGraphics = Graphics.FromImage(textBitmap))
{
using
(var drawFont =
new
System.Drawing.Font(fontName, fontSize, GraphicsUnit.Pixel))
{
return
Convert.ToInt32(drawGraphics.MeasureString(text, drawFont).Width);
}
}
}
}
And then I have an extension method:
public
static
Unit AutoDropDownWidth(
this
RadComboBox comboBox)
{
var rcbWidth = Utilities.TextWidth(comboBox.Items.OrderByDescending(i => i.Text.Length).Take(1).Select(i => i.Text).First());
return
rcbWidth <= comboBox.Width.Value ? comboBox.Width : rcbWidth;
}
So, in my code behind I just have something like:
rcbSalesReps.DropDownWidth = rcbSalesReps.AutoDropDownWidth();
Just something to consider. To me, if I look at the attachments, I think the "just right" version looks much better than the "too short" one.
I'm open to any ideas or suggestions!
Thanks,
Andrew