gpt4 book ai didi

c# - ComboBox.SelectedValue 不工作

转载 作者:行者123 更新时间:2023-11-30 13:58:00 28 4
gpt4 key购买 nike

这段代码有什么问题?

myComboBox.Items.Clear();
myComboBox.Items.AddRange(new string[]{"one","two"});
myComboBox.SelectedValue = "one";

它显示时没有任何选择。

最佳答案

如果您像这样填充组合框:

myComboBox.Items.AddRange(new string[]{"one","two"});

您必须使用 ComboBox.SelectedItemComboBox.SelectedIndex设置/获取所选项目的属性:

myComboBox.SelectedItem = "one"; //or
myComboBox.SelectedIndex = 0;

The ComboBox.SelectedValue property is inherited fromListControl and must be used ONLY when:

  • the control is bound to a DataSource
  • and ValueMember and DisplayMember properties are definied.

关于c# - ComboBox.SelectedValue 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18730262/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com