Hi SUJAYS,
Observable collection represents a dynamic data collection that provides notifications when items get added or removed, or when the whole list is refreshed.
For more details refer below link.
ObservableCollection Class
Refer following code to add and remove items from observable collection.
Model
C#
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
VB.Net
Public Class Person
Public Property Name As String
Public Property Age As Integer
End Class
Namespaces
C#
using System.Collections.ObjectModel;
VB.Net
Imports System.Collections.ObjectModel
Code
C#
ObservableCollection<Person> persons = new ObservableCollection<Person>();
// Adding object to ObservableCollection.
persons.Add(new Person { Name = "Mudassar Khan", Age = 38 });
persons.Add(new Person { Name = "Dharmendra Das", Age = 35 });
// Remove object from ObservableCollection.
persons.Remove(persons.Where(i => i.Name == "Dharmendra Das").SingleOrDefault());
VB.Net
Dim persons As ObservableCollection(Of Person) = New ObservableCollection(Of Person)()
' Adding object to ObservableCollection.
persons.Add(New Person With {.Name = "Mudassar Khan", .Age = 38})
persons.Add(New Person With {.Name = "Dharmendra Das", .Age = 35})
' Remove object from ObservableCollection.
persons.Remove(persons.Where(Function(i) i.Name = "Dharmendra Das").SingleOrDefault())
Screenshots
After adding item
After removing item