我有一个从数据库查询中填充的Customers类的ObservableCollection。由于表格是如何加入的,我有时会得到一次输入(Bill的邮寄地址不同于他的邮寄地址),两次出现在数据中。
每个客户行都有一个ID作为唯一的主键,当有人从绑定的ListView中选择一行时,这就是我用来提取更多客户信息的东西。 在这个程序的WinForms版本中,我会搜索ListView中的CustomerID,如果发现我会避免再次插入它。WPF ObservableCollection中的唯一条目
ObservableCollection似乎没有能力轻易告诉我一个CustomerID是否已经存在于一个集合的类实例中,所以我想知道处理这个问题的最好方法是什么。
的想法我到目前为止有:
' Not sure how to make this work, since the CustomerID and Name would be the same, but the city, state, zip might not be.'
t = new classCustomer(CustomerID, CustomerName, City, State, Zip)
if not sr.contains(t) then
sr.Add(t)
end if
Possibly figure out how to create an ObservableDictionary, but so far all the examples are in C#, and it may take me a while to port it over to VB.net
任何人都知道一个更好的实施?
我会说这将更好地解决在查询本身,而不是在UI – jeroenh 2011-05-13 21:20:01
我会同意你,但我不知道这是多么实际。对于高度规范化的数据库来说,这是一个真正复杂的查询,有10个左右的连接。我大概可以简化查询,但这会更好,并在更多领域有用。 – AndyD273 2011-05-15 23:19:24