0

I am using the following technique for populating a combobox in 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";

Would it be possible to achieve the same result, but with only selecting the two relevant columns (CustomerID and CustomerRef) from customer rather than all columns.

Is there a better way to do this?

Thank you...

4

2 回答 2

0

您可以使用 DropDown 事件来检索您的数据并制作组合框

Customers.Text=[请选择]

默认。

于 2013-09-25T16:42:58.043 回答
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";
于 2013-09-25T16:07:16.617 回答