combobox focus on beginning of text after selection

自作多情 提交于 2019-12-20 03:17:23

问题


I'm using winforms with a combobox that has a wider drop down width than it's size. when a user selects something from there, it displays just the ending of the text instead of the beginning. how do i default it to show text starting with the start of the string?

ie. combobox has items

  • Atlanta Georgia
  • Athens Georgia
  • Miami Florida
  • ....

and the user picks one and all they see in the box afterwards is "a Georgia"

no, i unfortunately don't have the realestate to make the combobox bigger, and the order of the words in the list won't be changed.

Thanks!


回答1:


The trick is to call the select after the SelectedIndexChanged event happens:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
  this.BeginInvoke(new Action(() => { comboBox1.Select(0, 0); }));
}



回答2:


Select position zero by force:

comboBox1.Select(0, 0);

...after the selection is complete and locked in, just call Select.

You could also use:

comboBox1.SelectAll();

...if you want it all highlighted.



来源:https://stackoverflow.com/questions/18260259/combobox-focus-on-beginning-of-text-after-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!