我有一个窗体上的组合框控件,它从某些数据源中提取其数据(显示和值)。在另一边,我有一排桌子。我希望当应用程序正在开发时,组合框将selectedvalue或selecteditem设置为上一行中一列的值。当用户更改组合框时,它将保持更改为行。我试图将SelectedValue绑定到这个列,但它不起作用。 Combobox仅设置开始到第一个项目。什么是问题?组合框数据绑定
编辑
这是一个双赢的窗体项目。 这里是绑定代码:
this.comboBoxCountries = new System.Windows.Forms.ComboBox();
this.countriesBindingSource = new System.Windows.Forms.BindingSource(this.components);
//
// comboBoxCountries
//
this.comboBoxCountries.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.searchCriteriaBindingSource, "Postcode", true));
this.comboBoxCountries.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.searchCriteriaBindingSource, "CountryCode", true));
this.comboBoxCountries.DataSource = this.countriesBindingSource;
this.comboBoxCountries.DisplayMember = "Name";
this.comboBoxCountries.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxCountries.FormattingEnabled = true;
this.comboBoxCountries.Location = new System.Drawing.Point(190, 19);
this.comboBoxCountries.Name = "comboBoxCountries";
this.comboBoxCountries.Size = new System.Drawing.Size(156, 21);
this.comboBoxCountries.TabIndex = 2;
this.comboBoxCountries.ValueMember = "Code";
this.comboBoxCountries.SelectedValueChanged += new System.EventHandler(this.comboBoxCountries_SelectedValueChanged);
//
// countriesBindingSource
//
this.countriesBindingSource.DataMember = "Countries";
this.countriesBindingSource.DataSource = this.dbDataSetCountries;
//
// dbDataSetCountries
//
this.dbDataSetCountries.DataSetName = "dbDataSetCountries";
this.dbDataSetCountries.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
//
// searchCriteriaBindingSource
//
this.searchCriteriaBindingSource.AllowNew = false;
this.searchCriteriaBindingSource.DataMember = "SearchCriteria";
this.searchCriteriaBindingSource.DataSource = this.dbDataSetSearchCriteria;
this.searchCriteriaBindingSource.BindingComplete += new System.Windows.Forms.BindingCompleteEventHandler(this.searchCriteriaBindingSource_BindingComplete);
//
// dbDataSetSearchCriteria
//
this.dbDataSetSearchCriteria.DataSetName = "dbDataSetSearchCriteria";
this.dbDataSetSearchCriteria.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
EDIT2
正如我在我下面的评论中提到,我还有一个textbox
被绑定到相同绑定源的其他DataMember
和textbox
工作精细。它具有适当的价值。当我在同一个数据库上更改DataMember
时,我在其中设置了组合框的selectedvalue
属性,它也显示出良好的结果并正常工作。
在此先感谢!
尝试把,如果结合中(是!回发)功能 – prema 2011-12-21 04:59:34
哪种技术是winforms/wpf/asp.net?你试过的代码是什么? – Maheep 2011-12-21 05:00:14
请发布您的数据绑定代码(ItemsSource和SelectedItem/Value)以及数据源定义。 – 2011-12-21 05:02:31