开发者

ComboBox Value shows the end portion after Selecting an Item

I have a ComboBox in my C# Winform. Some of the Item texts are larger than the size of the ComboBox. Whenever I select these values, the end portion is visible. How can I 开发者_如何学Goensure that, the beginning portion is shown.

For example,

Consider the items: {"small","big text selection"}

Now, the ComboBox is large enough to show 8 characters. When I select, "big text selection",

I can only see, "election", but I would like to view "big text" instead.


Is it significantly to you to use DropDownStyle equal to DropDown? In this style combobox have an editor, so when yoou select new value from the list it display in the editor and cursor position set at end of text. So in this case you should send HOME button code to the combobox editor this will move cursor at the start of line. You can do that as shown below:

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SendKeys.Send("{HOME}");
    }

But if DropDown style is not significant to you just change it to DropDownList and you will have desired behavour.


In the SelectedIndexChanged event create a Timer:

Timer timer = new Timer();
timer.Interval = 10;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();

And in its Tick:

void timer_Tick(object sender, EventArgs e)
{
    comboBox1.Select(0, 0);
    (sender as Timer).Stop();
    (sender as Timer).Dispose();
}

The Select call will achieve what you're after.


You can also look at expanding the value dynamically or use a tooltip for large items..

I explained it here for how to do it for Listbox:

http://blogs.msdn.com/b/sajoshi/archive/2010/06/15/asp-net-mvc-creating-a-single-select-list-box-and-showing-tooltip-for-lengthy-items.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜