在Combobox中显示无数据,更改两个属性 AutoCompleteMode ---- SuggestAppend和AutoCompleteSource ---我尝试过的CustomeSource代码
$(window).on('load', function(){
var delay = 5000;
If ( $('.bg').hasClass('pressed') ) {
delay = 2000; //set delay to 2 sec,
}
$('.btn').on('click', function() {
$('.bg').addClass('pressed');
});
$('.bg').animate({
'background-color': 'red'
}, delay);
});
AutoCompleteStringCollection对象具有所有项目,但组合框不显示任何内容
答案 0 :(得分:0)
您需要设置以下属性:
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
这是完整的代码。
AutoCompleteStringCollection mycol = new AutoCompleteStringCollection {
"Select product"
};
using (SqlConnection con = createconnection()) {
using (SqlCommand cmd = new SqlCommand ("SELECT Pname FROM product")) {
using (SqlDataReader reader = cmd.ExecuteReader ()) {
while (reader.Read ()) {
mycol.Add (Convert.ToString (reader[0]));
}
}
}
}
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
comboBox1.AutoCompleteCustomSource = mycol;
编辑: 我想你想要在下拉列表中显示项目而不是自动完成。在这种情况下,您需要添加项目。
comboBox1.Items.Add("Select product");
using (SqlConnection con = createconnection()) {
using (SqlCommand cmd = new SqlCommand ("SELECT Pname FROM product")) {
using (SqlDataReader reader = cmd.ExecuteReader ()) {
while (reader.Read ()) {
comboBox1.Items.Add (Convert.ToString (reader[0]));
}
}
}
}