[英]Winform Set ComboBox Placeholder
我有以下填充的ComboBox控件,如下所示
DataTable dt2 = InfoPCMS.db.executeSelectQuery("select * from Customer");
txtCustomer.DataSource = dt2;
txtCustomer.ValueMember = "Id";
txtCustomer.DisplayMember = "CustomerName";
如何設置占位符,說“選擇客戶”
這不能解決您的問題,但可以解決您的問題。 我認為有一種更好的方法可以完成這項工作,但這可行:
DataTable dt2 = InfoPCMS.db.executeSelectQuery("select * from Customer");
foreach (DataRow row in dt2.Rows)
{
ComboboxItem newItem = newComboboxItem(row["id"], row["CustomerName"]);
txtCustomer.Items.Add(newItem);
}
txtCustomer.Items.Insert(0,"Select a customer");
txtCustomer.SelectedIndex = 0;
public class ComboboxItem
{
public string Text { get; set; }
public object Value { get; set; }
public ComboboxItem(object val, string txt)
{
this.Value = val;
this.Text = txt;
}
public override string ToString()
{
return Text;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.