0
通常我填comoboBox這樣:如何使用AutoComplete從CombBox中獲取SelectedValue?
combo.DataSource = dt;
combo.ValueMember = "id";
combo.DisplayMember = "name";
,容易我可以選擇的值與此代碼
int i = convert.toint(combo.selectedValue);
但我使用自動完成後,我無法得到它:
con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=ACDB;Integrated Security=True;Pooling=False");
da = new SqlDataAdapter("SELECT id, name from usersTBL", con);
da.Fill(dt);
AutoCompleteStringCollection datasource = new AutoCompleteStringCollection();
for (int i = 0; i < dt.Rows.Count; i++)
{
datasource.Add(dt.Rows[i][1].ToString());
}
this.comboSearch.AutoCompleteCustomSource = datasource;
this.comboSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
this.comboSearch.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.comboSearch.DataSource = dt;
this.comboSearch.DisplayMember = "name";
this.comboSearch.ValueMember= "id";
現在如果我手動從組合框中選擇一個項目,我可以得到SelectedValue,但是如果我使用自動完成,我不能。當我從ComboBox中搜索Selected item時,我想獲取SelectedValue。
是的,我這樣做,但在我的代碼,其我的寫錯誤只有 –
*當*您檢查SelectedValue屬性? – LarsTech
你嘗試過'comboSearch.Text'嗎? – NPras