所以我有一個名爲類CustomerCollection
綁定的對象的兩個字段從列表
class CustomerCollection
{
public List<Customer> Customers { get; private set; }
...
}
擁有的customers
class Customer
{
public String ID { get; private set; }
public String Name { get; private set; }
public Customer(String id, String name)
{
ID = id;
Name = name;
}
}
名單有沒有去綁定組合框和文本使得組合框將在Customer Collection
中顯示Customers
的所有可能的ID,文本框將顯示所選客戶的名稱?
編輯: 所以這裏就是我試過
private void InitializeCustomerCollection()
{
var customerCollection = new CustomerCollection();
cmbx_custID.DataSource = customerCollection.Customers;
}
但是,這並不工作,導致組合框充滿
X.Collections.Customer
X.Collections.Customer
X.Collections.Customer
是的,這是可能的。你在使用什麼平臺? WPF?的WinForms? ASP.NET? – PoweredByOrange
Winform。我忘了標記它。抱歉。 – Wusiji
我不知道如何在WinForms中完成此操作。然而,你看到像你這樣的輸出的原因是因爲它不知道如何顯示你當前的對象。您或者需要爲其提供DisplayMemberPath(這是xaml/wpf中的內容),或者重載類.ToString()方法以使用您的客戶的名稱。 – gleng