Justin
Justin

Reputation: 219

how to set display member of combo box statically before clicking drop down list at run time

I want to display member of combo box(add) in windows form before clicking drop list, the members which I'm trying to display are "Add, delete, clear, modify". But despite of setting display member property equal to "add" from property window statically, I'm unable to see "add" in combo box at run time before clicking drop down list of combo box.

Could anyone please tell me what's wrong I'm doing?

Upvotes: 0

Views: 1565

Answers (4)

Skorpioh
Skorpioh

Reputation: 1355

In your case, given the fact that you already know what values the dropdownlist will have, you can just say myComboBox.Text = "Add"

Have fun coding!

Upvotes: 0

JCTLK
JCTLK

Reputation: 2165

I guess that

ComboBoxName.SelectedItem = "Add";

should work. You can put this in the Form Load method.

Upvotes: 2

A_Nabelsi
A_Nabelsi

Reputation: 2574

yourCombo.SelectedIndex = 0;

or

yourCombo.SelectedItem = "Add";

Upvotes: 1

Neil Knight
Neil Knight

Reputation: 48547

Change your SelectedIndex to 0 in your code and this will select the first item in the list.

myComboBox.SelectedIndex = 0;

Upvotes: 2

Related Questions