Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to set default value of combobox as "--select--" in windowsform application
Posted

You got 2 possibilities:
Combobox.SetCurrentValue[^]
SetCurrentValue sets the value of a dependency property without changing its value source.
or
Combobox.SetValue[^]
SetValue sets the local value of a dependency property.

Check other Combobox[^] properties (SelectedValue, SelectedIndex, SelectedItem) depending of your current .NET Framework version.
 
Share this answer
 
C#
ComboBox myCombo;

private void SetAsDefault()
{
// this sets the combobox to the first item
// to change which item will be selected change the index;
// if you want to set the combobox to have nothing selected change index to -1 
int index = 0;
myCombo.SelectedIndex = index;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900