开发者

ComboBox filling

开发者 https://www.devze.com 2023-04-06 11:18 出处:网络
I have a problem filling my ComboxBox. Here´s my code: string[] test = { \"Ausgaben\", \"Eingaben\" };

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 sele开发者_如何转开发cted 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?


Use:

cbEinAus.SelectedIndex = 0;

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


Try

cbEinAus.Items[vbEinAus.SelectedIndex]

instead of SelectedItem. usually works for me.


Try setting the SelectedItem as cbEinAus.Items[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?


cbEinAus.SelectedIndex = 0;

replace item to index

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号