我有一個窗體上的組合框控件,它從某些數據源中提取其數據(顯示和值)。在另一邊,我有一排桌子。我希望當應用程序正在開發時,組合框將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