1
我试图将对象添加到组合框中,并使用SelectedValue
属性在组合框中选择和项目,但它不起作用:SelectedValue
在赋值后仍为空。ComboBox SelectedValue属性不起作用
class ComboBoxItem
{
string name;
object value;
public string Name { get { return name; } }
public object Value { get { return value; } }
public ComboBoxItem(string name, object value)
{
this.name = name;
this.value = value;
}
public override bool Equals(object obj)
{
ComboBoxItem item = obj as ComboBoxItem;
return item!=null && Value.Equals(item.Value);
}
}
operatorComboBox.Items.Add(new ComboBoxItem("Gleich", SearchOperator.OpEquals));
operatorComboBox.Items.Add(new ComboBoxItem("Ungleich", SearchOperator.OpNotEquals));
operatorComboBox.ValueMember="Value";
//SelectedValue is still null after this statement
operatorComboBox.SelectedValue = SearchOperator.OpNotEquals;