问题
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