c# - Set SelectedIndex in WinForms ComboBox in OnLoad method -


if set selectedindex of combobox in onload method, text inside combobox gets selected well.

protected override void onload(eventargs e) {     base.onload(e);     combobox.items.add("zero");     combobox.items.add("one");     combobox.items.add("two");      combobox.selectedindex = 2; } 

text inside combobox selected when index set inside onload

if use onshown method setting selectedindex works expected:

protected override void onshown(eventargs e) {     base.onshown(e);     combobox.selectedindex = 2; } 

text inside combobox not selected when index set inside onshown

why happen , how can avoid behavior? inside usercontrol, there no onshown method can used. therefore workaround won't work custum usercontrol.

if don't want focus combo box change focus other control.

like

textbox1.select();


Comments