【发布时间】:2011-11-07 02:37:06
【问题描述】:
我有一个数据表,其中包含我想用于列表的列。为了测试我的employeeList,我添加了一个ListBox,然后在代码中添加了lstEmployees.ItemsSource = employeeList(cboStore.Text); 我知道这不是WPF应用程序的“最佳实践”,但我我是 XAML、WPF 和 C#(来自 VB.Net Winforms)的新手,所以我专注于首先让事情正常工作,然后我可以稍后重构(是的,我会的!)。
我正在用下面的代码填写我的列表,这让我得到了正确的字段,因为我可以在调试器中看到正确的值。但是在列表框中,我看到了这个 ManpowerManager.MainWindow+Employee。作为列出的项目。需要做什么才能查看 LoginId 值?
private static List<Employee> employeeList(string store)
{
List<Employee> employeeList= default(List<Employee>);
employeeList = new List<Employee>();
using (DataTable dt = Logins.getDataset(store, "Manpower_SelectLogins"))
{
foreach (DataRow dr in dt.Rows)
{
employeeList.Add(new Employee(dr["LoginId"].ToString()));
}
}
return employeeList;
}
此时我没有绑定它,因为 ListBox 只是一个测试。
【问题讨论】: