简体   繁体   English

如何在datagrid wpf中检入项在某个列(在某个属性中)是否存在或不存在

[英]how to check in datagrid wpf if item exists or no in a certain column (in a certain property)

Question 1 : 问题1:

i have a code like this 我有这样的代码

Public TheList As New List(Of Server)

the server class contains a property called "ID" i want to search if the list contains an item with the "ID" property (integer) how can i do such a thing ? 服务器类包含一个名为“ ID”的属性,如果列表包含具有“ ID”属性(整数)的项目,我想搜索该如何处理?

Question 2 : 问题2 :

i have a datagrid with the property Itemssource set to {Binding TheList} will it auto update the list and the UI to show the new added items to "TheList" or no ? 我有一个数据网格,其属性Itemssource设置为{Binding TheList},它将自动更新列表和UI以将新添加的项目显示为“ TheList”还是否? if no how can i make it update ? 如果没有,我该如何更新?

answer in c# or vb thanks . 用C#或VB回答谢谢。

Q1: TheList.Find(Function(x) x.ID = 1234) Q1: TheList.Find(Function(x) x.ID = 1234)

Q2: Instead of a list you could better use an ObservableCollection instead of List . 问题2:最好使用ObservableCollection代替List而不要使用List ObservableCollection does the notification automatically. ObservableCollection自动执行通知。 Not sure if you could substitute it in your code, but it might be worth to try. 不知道是否可以在代码中替换它,但是值得一试。 So probably use: ObservableCollection(Of Server) instead of List(Of Server) . 因此可能使用: ObservableCollection(Of Server)而不是List(Of Server) At least, List will not do the notification automatically. 至少, List不会自动进行通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM