0

I have a problem filling my ComboxBox. Here´s my code:

string[] test = { "Ausgaben", "Eingaben" };
foreach (string r in test)
{
   cbEinAus.Items.Add(r);
}

The values from the string array are in the ComboBox, but the selected item is a empty string. I want one of this two string from the array to be my selected item.

I already tried with the SelectedItem property, but that doesn´t work.

Maybe its a simple solution... Can anybody help me please?

SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
Harald
  • 43
  • 1
  • 5

5 Answers5

1

Use:

cbEinAus.SelectedIndex = 0;

You can replace the 0 with the zero based index of whichever item you want to select.

CodingGorilla
  • 19,612
  • 4
  • 45
  • 65
0
cbEinAus.SelectedIndex = 0;

replace item to index

kleopatra
  • 51,061
  • 28
  • 99
  • 211
jasel
  • 31
  • 1
  • 2
  • 5
0

Try

cbEinAus.Items[vbEinAus.SelectedIndex]

instead of SelectedItem. usually works for me.

Neil N
  • 24,862
  • 16
  • 85
  • 145
0

Try setting the SelectedItem as cbEinAus.Items[0]

V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
0

You can set the Text property.

cbEinAus.Text = test[0];

More examples can be found at How do I set the selected item in a comboBox to match my string?

Community
  • 1
  • 1
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184