简体   繁体   中英

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

Question 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 ?

Question 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 ? if no how can i make it update ?

answer in c# or vb thanks .

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

Q2: Instead of a list you could better use an ObservableCollection instead of List . ObservableCollection does the notification automatically. 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) . At least, List will not do the notification automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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