我使用以下技术在winforms中填充组合框:
var customer = (new Customer[] { new Customer { CustomerID = -1, CustomerRef = "[Please Select]" } }).Concat(
from c in ctx.Customers
orderby c.CustomerRef ascending
select c).ToList();
cboCustomerRef.DataSource = customer;
cboCustomerRef.ValueMember = "CustomerID";
cboCustomerRef.DisplayMember = "CustomerRef";
是否可以实现相同的结果,但只从客户而不是所有列中选择两个相关列(CustomerID和CustomerRef)。
有更好的方法吗?
谢谢...
答案 0 :(得分:0)
试试这个
var customers =
from c in ctx.Customers
orderby c.CustomerRef ascending
select new { CustomerId = c.CustomerID, CustomerRef = c.CustomerRef }).ToList();
customers.Insert(0, new { CustomerID = -1, CustomerRef = "[Please Select]"});
cboCustomerRef.DataSource = customers;
cboCustomerRef.ValueMember = "CustomerID";
cboCustomerRef.DisplayMember = "CustomerRef";
答案 1 :(得分:0)
您可以使用DropDown事件来检索您的数据并进行制作 组合框
Customers.Text = [请选择]
默认情况下。