问题描述
的WinForms / .NET 3.5
Winforms / .Net 3.5
我现在用的dropdownstyle设置下拉列表中选择组合框(允许用户输入的数据)。
I am using a combobox with the dropdownstyle set to dropdown (allows users to enter data).
我遇到的问题是如何设置的组合框,因此从列表更新我的BindingSource与价值观,并在用户输入数据。
The problem I am having is with how to setup the combobox so it updates my bindingsource with values from the list and also when a user enters data.
例如组合框可能包含以下值:
For example the combobox may contain the following values:
红,白,蓝。但用户应能够进入的黑。
"Red", "White", "Blue". But the user should be able to enter "Black".
我尝试使用文本属性,但问题是我的组合框的显示值包括额外信息(code和说明),比值(仅code)。
I tried using the "Text" property but the problem is my combobox display values include extra information (code and a description) than the Value (only code).
我尝试添加绑定到ComboBox时使用的SelectedValue,但它只是从列表值和更新不是当用户输入数据。
I tried using SelectedValue when adding bindings to the combobox, but then it only updates with values from the list and not when a user enters data.
MyComboBox.DataBindings.Add("SelectedValue", MyBindingSource, "MyProperty", True, DataSourceUpdateMode.OnValidation)
任何想法?
推荐答案
我有同样的问题。我通过与DataBindings.Add法文本替换参数的SelectedValue解决了这个问题。MyComboBox.DataBindings.Add(文本,MyBindingSource,myProperty的,没错,DataSourceUpdateMode.OnValidation)
I had the same problem.I solved it by replacing the parameter "SelectedValue" with "Text" in DataBindings.Add method.MyComboBox.DataBindings.Add("Text", MyBindingSource, "MyProperty", True, DataSourceUpdateMode.OnValidation)
这篇关于组合框的WinForms数据绑定与DropDownStyle =下拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!